Castle Windsor: How do I inject all implementations of interface into a ctor?

前端 未结 4 2203
臣服心动
臣服心动 2020-12-28 14:59

I\'ve written an interface which is implemented by multiple classes. I want to write a Service class which will have all the registered implementations injected into its cto

4条回答
  •  独厮守ぢ
    2020-12-28 15:27

    I know this has already been answered, but I thought an example of how to add the CollectionResolver would be useful, so here it is.

    Call AddSubResolver before registering the components in the container, e.g.

    container = new WindsorContainer();
    container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));
    

    Register the components as normal:

    container.Register(
        Component.For().ImplementedBy(),
        Component.For().ImplementedBy(),
        Component.For().ImplementedBy()
    );
    

提交回复
热议问题