Dependency injection 如何使用Castle Windsor在代码中设置数组/列表依赖项?

Dependency injection 如何使用Castle Windsor在代码中设置数组/列表依赖项?,dependency-injection,castle-windsor,castle,Dependency Injection,Castle Windsor,Castle,我有以下课程: class Repository : IRepository class ReadOnlyRepository : Repository abstract class Command abstract CommandImpl : Command { public CommandImpl(Repository repository){} } class Service { public Service (Command[] commands){} } 我将其

我有以下课程:

class Repository : IRepository
class ReadOnlyRepository : Repository

abstract class Command
abstract CommandImpl : Command
{
     public CommandImpl(Repository repository){}
}

class Service
{
    public Service (Command[] commands){}
}
我将其以代码注册如下:

var container = new Container("WindsorCOntainer.config");
var container = new WindsorContainer(new XmlInterpreter("WindsorConfig.xml"));
container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));
container.AddComponent("repository", typeof(RentServiceRepository));
container.Resolve<RentServiceRepository>();
container.AddComponent("command", typeof(COmmandImpl));
container.AddComponent("rentService", typeof (RentService));
container.Resolve<RentService>(); // Fails here
var container=新容器(“WindsorCOntainer.config”);
var容器=新的WindsorContainer(新的xml解释器(“WindsorConfig.xml”);
container.Kernel.Resolver.AddSubResolver(新的ArrayResolver(container.Kernel));
container.AddComponent(“存储库”,类型为(RentServiceRepository));
container.Resolve();
AddComponent(“命令”,typeof(COmmandImpl));
container.AddComponent(“rentService”,typeof(rentService));
container.Resolve();//这里失败了
我收到消息“RentService正在等待依赖项命令”

我做错了什么?


谢谢,

您不是将
CommandImpl
注册为
Command
,而是将其注册为
CommandImpl

如果您这样做:

container.Register(Component.For<Command>().ImplementedBy<CommandImpl>());
container.Register(Component.For().ImplementedBy());
会有用的

我建议你熟悉一下,尤其是