2015-10-15 34 views
0

我使用hk2作爲CDI引擎。 我有2嵌套注射如以下代碼:HK2 InstantiationService嵌套注入

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)。爲了(兒子。類)。在(RequestScoped.class) bindFactory(GrandSonFactory.class)。爲了(GrandSon.class)。在(RequestScoped.class)

現在我想只是用InstantionService.getInstantiationData()從獲得描述符數據c在GrandSon類中的父類。特別是我需要回溯到調用Root類來檢查注入者父類。我可以從Son類的factory.provide方法獲取數據,但我無法從grandSon類獲取有效的getInstantiationdata()。 我的代碼有什麼問題?

+0

在上面的代碼中,我沒有看到誰在提供FirstSon?我看到Son和GrandSon的工廠提供商,但不是FirstSon。 – jwells131313

+0

對不起firstson是兒子...我剛纔編輯 – Alex

+0

獲得工廠服務時,InstantiationService可能存在問題。我會寫一個單元測試,並找出 – jwells131313

回答

0

這似乎是HK2中的一個錯誤。我已經進入以下JIRA:

Nested Factory Instantation Service Issue

一旦這個錯誤得到固定,我會更新這個答案。我已經檢查了一個失敗的測試,證明問題

+0

以及...謝謝!我會'檢查它! – Alex

+0

底層的bug已經修復,但現在需要經過發佈週期才能讓澤西撿起它 – jwells131313

+0

這太棒了......謝謝... – Alex