How do I configure a decorator with Castle Windsor?

好久不见. 提交于 2019-12-02 13:13:53

In order to allow DecoratingIsFun to decorate ForReal, you need to ensure that DecoratingIsFun is registered before ForReal - then Windsor will correctly resolve the decorator and satisfy its dependency with the next registration of something that implements IAmUsedTwice.

But since you're using XML to register the first service, I don't know how to achieve that, since the XML is sucked up when you instantiate WindsorContainer.

But why are you using XML in the first place? Is it because you don't think that you can use XML to configure components unless you're also using it to register them?

If that is the case, you should reduce the XML to something like this:

<component id="forReal">
    <parameters>
        <iNeed>${iNeed}</iNeed>        
    </parameters>
</component>

and move the registration to your code, allowing you to control the order of registration. Then, make sure that ForReal is registered with .Named("forReal"), allowing the configuration to be matched when the instance is resolved.

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