registering open generic decorators for typed implementations in castle windsor

后端 未结 1 1627
南旧
南旧 2020-12-21 23:00

While trying to coerce Windsor into wrapping an implementation with a random number of decorators, i\'ve stumbled upon the following:

i have 3 decorators and an impl

相关标签:
1条回答
  • 2020-12-21 23:15

    When windsor tries to resolve a component it will first try to resolve the more specific interface. So when you register Component.For it will prefer to resolve this over an open generic type.

    If the same interface is registered multiple times, it will use the first one specified.

    So if you don't uncommment the line your application will resolve implementation since this is the most specific component.

    If you do uncomment the line decorator1 will be resolved and indeed the magic starts. The decorator will now start looking for the first registered component that satisfies it's constructor, in this case that would be decorator1 again (you did notice that your output show decorator1 2 times ?). Which will the resolve the next registered component and so on till it comes to the actual implementation.

    So the only thing I can think about is not registering decorator1 as an open generic but as a specific type.

    Kind regards, Marwijn.

    0 讨论(0)
提交回复
热议问题