在模块注释@Module中声明子组件的示例(subcomponents = ...)

时间:2019-01-17 10:58:25

标签: android dagger-2 dagger

在匕首subcomponent中声明module annotation的用例是什么?例如

@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.

1 个答案:

答案 0 :(得分:0)

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

我有组件A和模块ModuleA和组件B。如果您在subcomponents = B.class中指定ModuleA,则匕首将不会编译为

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

除非组件BA的子组件。