如何在 Spring.Net 中注入层次结构的依赖
如何定义配置以将依赖项注入到以下对象层次结构:
RootObject
- ContentObject
- L11Object
- L12Object
- L21Object
.etc.
RootObject
依赖于 ImportantObject
且 ContentObject
依赖于 另一个对象
。 为了定义这些依赖项,我定义了以下内容:
<object name="RootObject" type="...." abstract="true">
<constructor-args ../>
</object>
<object name="ContentObject" type="...." abstract="true" parent="RootObject">
<constructor-args ../>
</object>
一切正常,但 Spring.Net 需要在配置中定义我的对象的层次结构。 是否可以使用“自动发现”之类的方式通过定义 parent="..."
来不重复配置中的继承层次结构?
是的,我知道 Unity 1.0+ 比 Spring.Net 解决这个问题要好得多,但我别无选择,我应该使用 Spring.Net。
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="RootObject">
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来你想要自动装配...类似这样的东西应该可以工作:
这假设有问题的类型使用构造函数注入模式,但是 IIRC 还支持属性注入。
即使
default-autowire
定义了自动装配的默认行为,您仍然可以在可能需要它的object
元素中覆盖它。It sounds like you want Auto-wiring... Something like this ought to work:
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 thoseobject
elements where it might be required.