Search code examples
javadependency-injectionguicedagger

Is there an equivalent for Guice install(new ModuleA) in Dagger?


I'm trying to migrate a project from Guice to Dagger, and I can't figure out what to do with modules including other modules using install. How would I switch even a really basic example like this to Dagger?

public class ModuleA extends AbstractModule {

  public ModuleA() {
    ...
  }

  @Override
  protected void configure() {
    install(new ModuleB());
  }
}

Where ModuleB would provide its own dependencies.

What would the dagger equivalent of this look like? Thank you for the help!


Solution

  • To make one module include another in Dagger, use includes in your @Module annotation:

    @Module(includes = {ModuleB.class})
    public class ModuleA {
        // ...
    }