第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

牙簽不會在注入的實例中注入依賴項

牙簽不會在注入的實例中注入依賴項

MMTTMM 2022-05-20 18:28:41
我為 Toothpick 和 Authenticator 創(chuàng)建了 Activity、ViewModel、Modules。@Singletonpublic class GetSmsViewModel {    @Inject Application app;    @Inject Authenticator authenticator;...}public class GetSmsActivity extends AppCompatActivity {    private Scope appScope;    @Inject GetSmsViewModel mGetSmsViewModel;...    @Override    protected void onCreate(Bundle savedInstanceState) {        appScope = Toothpick.openScope(getApplication());        appScope.installModules(new DIModule(getApplication()), new DataModule());        super.onCreate(savedInstanceState);        Toothpick.inject(this, appScope);   ...   }}public class DIModule extends Module {    public MagicDeliveryMainModule(Application application) {        bind(GetSmsViewModel.class).toInstance(new GetSmsViewModel());        bind(Application.class).toInstance(application);        bind(Authenticator.class).toInstance(new Authenticator());    }}在 Toothpick 的文檔中寫道:“如果 Toothpick 創(chuàng)建一個實例,它將始終注入其依賴項?!?, 但在 Toothpick.inject(this, appScope); 之后mGetSmsViewModel.app == null 和 mGetSmsViewModel.authenticator == null 。在 Toothpick.inject(mGetSmsViewModel, appScope); 之后 app 和 authenticationator 字段被注入。應(yīng)該是這樣嗎?
查看完整描述

1 回答

?
飲歌長嘯

TA貢獻1951條經(jīng)驗 獲得超3個贊

在您的示例中,牙簽沒有創(chuàng)建實例,您正在創(chuàng)建實例并綁定它。

要讓牙簽創(chuàng)建實例,需要綁定目標(biāo)實現(xiàn)類并提供注入構(gòu)造函數(shù)。


查看完整回答
反對 回復(fù) 2022-05-20
  • 1 回答
  • 0 關(guān)注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號