Skip to content

Instantly share code, notes, and snippets.

@shaunpanjabi
Created March 19, 2018 22:55
Show Gist options
  • Save shaunpanjabi/76f3c6c7e3b7c5b8625384197b3ae13d to your computer and use it in GitHub Desktop.
Save shaunpanjabi/76f3c6c7e3b7c5b8625384197b3ae13d to your computer and use it in GitHub Desktop.
Dagger 2 Providing a Component in a module
@Singleton
@Component(modules = LibraryAModule.class)
public interface LibraryAComponent {
@Component.Builder
interface Builder {
LibraryAComponent build()
}
SomeLibADep someLibADep();
}
@Module
public class LibraryAModule {
@Provides
@Singleton
SomeLibADep provideSomeLibADep() {
return new SomeLibADep();
}
}
@Module
public class LibraryBModule {
@Provides
@Singleton
LibraryAComponent provideLibraryAComponent() {
return DaggerLibraryAComponent
.builder()
.build();
}
@Provides
@Singleton
SomeDepThatNeedsLibA provideSomeDep(LibraryAComponent libraryA) {
return new SomeDepThatNeedsLibA(libraryA.someLibADep())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment