0
这是我想要实现的情况。通知有关创建子上下文对象的父上下文对象
public class ComponentRepository
{
public void Register(IComponent component)
{
// store component in collection
}
}
<!-- root context -->
<object id="Repository" type="NameSpace.ComponentRepository" />
<!-- child context (0 - n contexts) -->
<object id="Component" type="NameSpace.Component"/>
我想与ComponentRepository
注册所有IComponent
对象。我想这可以通过某种发布/订阅机制来完成,但我想保持我的类清洁(没有实现任何spring.net接口)。 达成此目的的最佳方法是什么?
你可以使用[方法注入](http://www.springframework.net/doc-latest/reference/html/objects.html#objects-method-injection)作为替代,使'ComponentRepository' IApplicationContextAware' ,举例来看我的答案在这里:http://stackoverflow.com/questions/5026711/possible-getobjectsoftype-replacement/5195658#5195658 – Marijn 2012-02-27 10:32:13
好主意的确使用方法替代品。 – tobsen 2012-02-27 11:33:50
我用了小小的扭曲的tobsen解决方案。我创建了新的'IApplicationContextAware'类,它将'Component'(而不是'ComponentRepository')作为依赖关系。然后,我使用'IConfigurableApplicationContext.ParentContext'来获取'ComponentRepository'并注册'Component'。谢谢你的帮助。 – Filip 2012-02-27 13:58:20