【发布时间】:2014-08-19 19:13:57
【问题描述】:
我有一个使用 Dagger 的 Android 应用。整个应用程序的某些部分我想为几个共享公共范围的活动添加范围对象图。以下模块位于根 ObjectGraph 中
@Module(
injects = {
MyApplication.class,
},
complete = false,
library = true)
public class BasicContextManagerModule {
private Context applicationContext;
public BasicContextManagerModule(Context applicationContext) {
this.applicationContext = applicationContext;
}
@Provides
Context getApplicationContext() {
return applicationContext;
}
}
然后我尝试通过existingObjectGraph.plus(new FileManagerModule());添加以下Module;
@Module(
injects = {
MyListActivity.class,
MyFileDetailActivity.class,
MyFileInfoActivity.class,
},
includes = BasicContextManagerModule.class
)
public class FileManagerModule {
@Provides
FileManager provideFileManager(Context context) {
return new FileManager(context);
}
}
但结果是
java.lang.UnsupportedOperationException: No no-args constructor com.myapp.core.modules.BasicContextManagerModule$$ModuleAdapter
有人可以帮我理解为什么加号不允许这样做吗?我从 dagger 文档中读到 plus 扩展了对象图,并且您可以拥有包含和添加到模块。但我一直没能做到这一点。
【问题讨论】:
标签: android dependency-injection include square dagger