Created
September 18, 2017 21:11
-
-
Save alex-y-su/50b4b18f7595342980c37c6ca0be541a to your computer and use it in GitHub Desktop.
This file contains 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
//------------------------------------------------------------------------------------ | |
//In android library | |
//------------------------------------------------------------------------------------ | |
@Module | |
@ProxyModule | |
class LibraryModule(val hostInjector: Injector) { | |
@Provides | |
fun proxyComponent() : IComponent = hostInjector.getInstance<IComponent>() | |
} | |
@Component | |
class LibraryComponent() { | |
@Provides | |
@Proxy | |
fun getLibraryModule(hostInjector: Injector) : LibraryModule(hostInjector) | |
} | |
class SomeFragmentInLibrary : Fragment { | |
override fun onCreate() { | |
//get | |
val appInjector = ... //somehow get app injector | |
val libInjector = Lightsaber.get().createChildInjector(appInjector, LibraryComponent()) | |
//resolve everything we need in lib | |
} | |
} | |
//------------------------------------------------------------------------------------ | |
//In anroid app | |
//------------------------------------------------------------------------------------ | |
@Module | |
class ApplicationModule() { | |
@Provides | |
fun component() : IComponent = ComponentImpl() | |
} | |
@Component | |
class ApplicationComponent { | |
@Provides | |
fun appModule() = ApplicationModule() | |
} | |
//We should pass this instance to library | |
val appInjector = Lightsaber.get().createInjector(ApplicationComponent()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment