【发布时间】:2015-04-09 01:04:54
【问题描述】:
我开始使用 Dagger,我使用的是 1.2 版本,我有以下场景:
模块:
@Module(injects = {
AuthenticationService.class
})
public class ServiceModule {
@Provides
AuthenticationService provideAuthenticationService() {
return ServiceFactory.buildService(AuthenticationService.class);
}
}
在我的应用程序类中,我创建了 ObjectGraph:
public class FoxyRastreabilidadeApplication extends Application {
private static FoxyRastreabilidadeApplication singleton;
@Override
public void onCreate() {
super.onCreate();
createObjectGraph();
singleton = this;
}
private void createObjectGraph() {
ObjectGraph.create(ServiceModule.class);
}
}
最后,在我的 LoginActivity 中,我尝试注入我的 AuthenticationService:
public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
private UserLoginTask mAuthTask = null;
@Inject
AuthenticationService authenticationService;
}
此时,当我尝试访问我的 AuthenticationService 实例时,它始终为空,这意味着它根本没有被注入,我调试了我的提供程序方法以确保它,所以,问题是,我错过了什么吗?如果有,是什么?
【问题讨论】:
标签: android dependency-injection dagger