1

我有以下课程:

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

我收到“RentService 正在等待依赖命令”的消息

我究竟做错了什么?

谢谢,

4

1 回答 1

2

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

如果你这样做:

container.Register(Component.For<Command>().ImplementedBy<CommandImpl>());

它会工作的。

我建议您熟悉文档,尤其是安装程序注册 API

于 2010-05-12T17:48:09.807 回答