前篇文章:
项目组件化集成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