How can I define configuration to inject dependencies to the following hierarchy of objects:
RootObject
- ContentObject
- L11Object
- L12Object
- L21Object
.etc.
The RootObject
has dependency to ImportantObject
and ContentObject
has dependency to AnotherObject
.
To define theses dependencies I defined the following:
<object name="RootObject" type="...." abstract="true">
<constructor-args ../>
</object>
<object name="ContentObject" type="...." abstract="true" parent="R开发者_如何学GoootObject">
<constructor-args ../>
</object>
All works fine, but Spring.Net requires define hierarchy of my's objects in configuration.
Is it posible to use somethink like "auto discovery" to do not repeate hierarchy of inheritance in configuration through define parent="..."
?
And yes, I know that Unity 1.0+ solves it much better than Spring.Net, but I have no choice and I should use Spring.Net.
It sounds like you want Auto-wiring... Something like this ought to work:
<objects xmlns="http://www.springframework.net"
default-autowire="constructor">
<object type="RootObject" />
<object type="ContentObject" />
<object type="L11Object" />
<object type="L12Object" />
<object type="L21Object" />
<!--etc.-->
</objects>
This assumes that the types in question utilizes the Constructor Injection pattern, but IIRC Property Injection is also supported.
Even though the default-autowire
defines a default behavior for Auto-wiring, you can still override it in those object
elements where it might be required.
精彩评论