2

What is the use case of declaring subcomponent in dagger module annotation?. e.g.

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

I have read the documentation, but couldn't find any example of usage.

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.
mallaudin
  • 4,744
  • 3
  • 36
  • 68
  • Does this answer your question? [Why are Dagger subcomponents declared in a module and not in the parent component directly?](https://stackoverflow.com/questions/55908839/why-are-dagger-subcomponents-declared-in-a-module-and-not-in-the-parent-componen) – Jeff Bowman Aug 18 '20 at 17:34

1 Answers1

0

You can specify Subcomponent classes that should be dependent on Component that your module is child of.

I have component A with module ModuleA and component B. If you specify subcomponents = B.class inside ModuleA, then dagger will not compile giving

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

unless component B is subcomponent of A.

Tuby
  • 3,158
  • 2
  • 17
  • 36