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

前端 未结 4 2216
臣服心动
臣服心动 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条回答
  •  猫巷女王i
    2020-12-28 15:17

    You have to use CollectionResolver. Check this Castle Windsor FAQ:

    Windsor, by default when you have dependency on IFoo[], IEnumerable or IList will check if you have a component registered for that exact type (array or list of IFoo), not if you have any components registered for IFoo (array of components, is not the same as a component which is an array). You can change the behavior to say "When you see array or list of IFoo just give me all IFoos you can get" you use CollectionResolver.

    Direct link to Castle Resolvers: Resolvers.

提交回复
热议问题