我使用hk2作为CDI引擎。我有2个嵌套注入,如下代码所示:
public class Root {
@Inject
Son son;
...
}
public class Son {
@Inject
GrandSon gs; //should i put it here?
...
}
public class GrandSon {
...
}这些是工厂类:
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类,检查已被注入的父类。我可以从子类的factory.provide方法获得数据,但不能从grandSon类获得有效的getInstantiationdata()。我的密码怎么了?
发布于 2015-10-22 17:27:02
https://stackoverflow.com/questions/33158148
复制相似问题