我有以下课程:
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正在等待依赖命令”的消息
我做错了什么?
谢谢,
答案 0 :(得分:2)
您未将CommandImpl
注册为Command
,而是将其注册为CommandImpl
。
如果你这样做:
container.Register(Component.For<Command>().ImplementedBy<CommandImpl>());
它会起作用。
我建议您熟悉the documentation,尤其是installers和registration API