我有一个使用Dagger的Android应用.整个应用程序的某些部分我想为几个共享共同范围的活动添加范围的ObjectGraphs.以下模块位于根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( 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
有人可以帮助我理解为什么加号不会允许这个?我从匕首文档中读到,扩展了对象图,你可以使用includes和addsTo Modules.但我无法做到这一点.
includes
表示模块将存在于同一子图中,如果不传递实例,Dagger将实例化它.
addsTo
表示引用的模块应该在图中(实际上在父图中),但Dagger不会为您提供.
你想要的是什么addsTo
.