Last active
May 23, 2017 11:22
-
-
Save maomaobug/35ea83706bbb6768be3c365e58ac009f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DemoApplication extends Application { | |
private AppComponent appComponent; | |
@Inject | |
TokenInterceptor tokenInterceptor; | |
@Inject | |
RealmConfiguration realmConfiguration; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
ApplicationContext.setContext(this); | |
// 初始化 AppComponent,初始化过程中需要“安装”各个 Module | |
mAppComponent = DaggerAppComponent.builder() | |
.appModule(new AppModule(this)) | |
.networkModule(new NetworkModule()) | |
.demoApiModule(new DemoApiModule()) | |
.build(); | |
// 依赖注入,所有 @Inject 的成员变量都将会被赋值, | |
// AppComponent中声明了 inject(SomeApplication app)方法 | |
mAppComponent.inject(this) | |
// 这里我们直接从 AppComponent 中获取 Retrofit 实例来初始 | |
// 化外部 Library, AppComponent 中声明了 getRetrofit()方法 | |
UploadAttach.getImpl().init(mAppComponent.getRetrofit()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment