android - 在模块注解@Module(subcomponents = ...)中声明子组件的例子

标签 android dagger-2 dagger

在 dagger module annotation 中声明 subcomponent 的用例是什么?。例如

@Module(subcomponents = ChildComponent.class)
public class ModuleB 

我已阅读文档,但找不到任何使用示例。

Any {@link Subcomponent}- or {@code @ProductionSubcomponent}-annotated classes which should be
   * children of the component in which this module is installed. A subcomponent may be listed in
   * more than one module in a component.

最佳答案

您可以指定子组件类,这些子组件类应该依赖于您的模块所属的组件。

我有组件 A 和模块 ModuleA 和组件 B。如果你在 ModuleA 中指定 subcomponents = B.class,那么 dagger 将不会编译给出

error: A doesn't have a @Subcomponent.Builder, which is required when used with @Module.subcomponents
@Module(subcomponents = {B.class})
^

除非组件 BA 的子组件。

关于android - 在模块注解@Module(subcomponents = ...)中声明子组件的例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54234408/

相关文章:

android - Dagger 2 在创建方法上获取空对象引用

带有 Dagger Hilt 的 Android 动态功能模块

java - Dagger 2 注释处理器未针对 Java Gradle IntelliJ 项目运行

java - 如何在非 Android Gradle Java 应用程序中使用 Dagger?

android - 使用 Dagger 注入(inject)依赖项时出现 ClassCastException

android - Android TextUtils 的用途是什么?

java - 在对话框中动态添加 View

android - 我如何检查用户是否接受了读/写联系人的权限?

android - 来自 Android 仪器测试的 "additional_test_output"?

java - 另一个 JAR 文件中的抽象模块