CDI エンジンとして hk2 を使用しています。以下のコードのように、2 つの入れ子になった注入があります。
public class Root {
@Inject
Son son;
...
}
public class Son {
@Inject
GrandSon gs; //should i put it here?
...
}
public class GrandSon {
...
}
Factory クラスは次のとおりです。
public class SonFactory implements Factory<Son>{
@Inject
InstantionService is;
@Inject
GrandSon gs; //should i put it here?
public Son provide(){
is.getInstantiationData()
return sonImpl;
}
public dispose(Son instance){
// destroy
}
}
public GrandsonFactory implements Factory <GrandSon>{
@Inject
InstantionService is
public GrandSon provide(){
is.getInstantiationData()
return sonImple;
}
public dispose(GrandSon instance){
// destroy
}
}
私は両方の工場を次のようにバインドしました: bindFactory(SonFactory.class).to(Son.class).in(RequestScoped.class) bindFactory(GrandSonFactory.class).to(GrandSon.class).in(RequestScoped.class)
ここで、InstantionService.getInstantiationData() を使用して、GrandSon クラス内の呼び出し元の親から記述子データを取得したいだけです。特に、被注入者の親を検査する呼び出し元の Root クラスまで戻る必要があります。Son クラスの factory.provide メソッドからデータを取得できますが、grandSon クラスから有効な getInstantiationdata() を取得できません。コードのどこが間違っていますか?