问题
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