Created
March 19, 2018 22:55
-
-
Save shaunpanjabi/76f3c6c7e3b7c5b8625384197b3ae13d to your computer and use it in GitHub Desktop.
Dagger 2 Providing a Component in a module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = LibraryAModule.class) | |
public interface LibraryAComponent { | |
@Component.Builder | |
interface Builder { | |
LibraryAComponent build() | |
} | |
SomeLibADep someLibADep(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class LibraryAModule { | |
@Provides | |
@Singleton | |
SomeLibADep provideSomeLibADep() { | |
return new SomeLibADep(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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