項目組件化MVP,Dagger2,ARouter使用

前篇文章:

項目組件化歷程(MVP+dagger2+ARouter)

項目組件化集成ARouter,Dagger2

在BaseApplication做以下處理
 

 private void initRouter(){
        ARouter.openLog();     // Print log
        ARouter.openDebug();
        ARouter.init(this);
    }
    public static BaseApplication getIns() {
        return mInstance;
    }
    private void initApplicationComponent() {
        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .build();
    }
    public static ApplicationComponent getApplicationComponent() {
        return mApplicationComponent;
    }

dagger2有一定門檻,不清楚怎麼用的可以網上看下怎麼使用
我要說的是在模塊化項目中去怎麼使用。

在公共組件中寫ApplicationComponent,ApplicaitonModule,然後Build一下會生成相對應的附屬文件,初始化就可以如下所寫了

mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .build();

當然在每個功能模塊中寫相應的component和module文件,怎麼寫可以參考下面的
Dagger2,MVP
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章