これは実装したい状況です。子コンテキストオブジェクトの作成について親コンテキストオブジェクトに通知する
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インターフェイスを実装しないでください)。 これを達成する最も良い方法は何ですか?
'ComponentRepository''を' IApplicationContextAware'にする代わりに[メソッドインジェクション](http://www.springframework.net/doc-latest/reference/html/objects.html#objects-method-injection)を使うことができます、例についてはここで私の答えを参照してください:http://stackoverflow.com/questions/5026711/possible-getobjectsoftype-replacement/5195658#5195658 – Marijn
確かにメソッドの置換えを使用することをお勧めします。 – tobsen
私はトゥベンセンのソリューションを少しねじれて使用しました。依存関係として(ComponentRepositoryの代わりに) 'Component'をとる新しい' IApplicationContextAware'クラスを作成しました。次に、 'IConfigurableApplicationContext.ParentContext'を使って' ComponentRepository'を取得し、 'Component'を登録しました。ご協力いただきありがとうございます。 – Filip