在 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})
^
除非组件 B
是 A
的子组件。
关于android - 在模块注解@Module(subcomponents = ...)中声明子组件的例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54234408/