registering open generic decorators for typed implementations in castle windsor

白昼怎懂夜的黑 提交于 2019-11-29 16:57:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!