Dagger ObjectGraph plus()包含根模块中模块的模块不断返回No no-args构造函数

 江湖小子的美好生活_498_416 发布于 2022-12-27 10:33

我有一个使用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.但我无法做到这一点.

1 个回答
  • includes 表示模块将存在于同一子图中,如果不传递实例,Dagger将实例化它.

    addsTo 表示引用的模块应该在图中(实际上在父图中),但Dagger不会为您提供.

    你想要的是什么addsTo.

    2022-12-27 10:36 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有