Using Castle Windsor configuration files is it possible to delegate to another item declaration?

泪湿孤枕 提交于 2019-12-12 20:13:52

问题


Using Castle-Windsor, is it possible to declare a type once and use this declaration for multiple Ids rather than writing it out in full each time.

E.g. we have class Widget that implements IFoo and we want the keys "IFoo.A" and "IFoo.B" to get a Widget from Castle. I want to do something like

<id="IFoo.Main"
 type="IFoo"
 service="Widget"/>

then

<id="IFoo.A"
 giveme="IFoo.Main/>

<id="IFoo.B"
 giveme="IFoo.Main/>

Thanks.


回答1:


What your are looking for is forwarded types I believe... take a look at these questions:

  • What are forwarded types in the context of castle windsor component registration
  • Does castle windsor support forwarded types via xml

Though not supported out of the box in xml config at the moment the second question has an answer that details how to do this by writing a simple facility.



来源:https://stackoverflow.com/questions/344019/using-castle-windsor-configuration-files-is-it-possible-to-delegate-to-another-i

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