代码之家  ›  专栏  ›  技术社区  ›  SharePoint Newbie

如何在Castle Windsor的代码中设置数组/列表依赖项?

  •  1
  • SharePoint Newbie  · 技术社区  · 16 年前

    我有以下课程:

    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正在等待依赖命令”

    我做错什么了?

    1 回复  |  直到 16 年前
        1
  •  2
  •   Krzysztof Kozmic    16 年前

    你没有注册 CommandImpl Command ,您将其注册为 命令impl .

    如果您这样做:

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

    the documentation ,尤其是 installers registration API

    推荐文章