0

I m using hk2 as CDI engine. I have 2 nested injection as in the code below:

public class Root {
@Inject
Son son;
 ...
}

public class Son {
@Inject
GrandSon gs; //should i put it here? 
  ...
}

public class GrandSon {

  ...
}

These are the Factory classes:

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
    }
}

i bound both factory as: bindFactory(SonFactory.class).to(Son.class).in(RequestScoped.class) bindFactory(GrandSonFactory.class).to(GrandSon.class).in(RequestScoped.class)

Now i want just using the InstantionService.getInstantiationData() to get descriptor data from the calling parent inside the GrandSon class. In particular i need to rise back till to the calling Root class inspecting the injectee parent. I can get data from the factory.provide method of Son class, but i cannot get a valid getInstantiationdata() from grandSon class. What am i wrong with code?

4

1 回答 1

0

这似乎是HK2中的一个错误。我已输入以下 JIRA:

嵌套工厂实例化服务问题

修复此错误后,我将更新此答案。我已经检查了一个失败的测试来证明这个问题

于 2015-10-22T17:27:02.257 回答