Skip to content

Instantly share code, notes, and snippets.

@Sinarahimi
Created January 20, 2020 12:36
Show Gist options
  • Save Sinarahimi/f8313dfdb9ac3d6fb03f69884a769df7 to your computer and use it in GitHub Desktop.
Save Sinarahimi/f8313dfdb9ac3d6fb03f69884a769df7 to your computer and use it in GitHub Desktop.
// resolve Default instance
get<ComponentInterface1>
// resolve Component1, casted as ComponentInterface1
koin.bind<ComponentInterface1,Component1>()
// resolve all instances matching ComponentInterface1: Default, Component1 & Component2
koin.getAll<ComponentInterface1>()
starting your module either by startKoin
startKoin { modules(coffeeAppModule) }
// or after start
loadKoinModules(coffeeAppModule)
// resolve CoffeeMaker
get()<CoffeeMaker>
// drop module's definitions & instances when you don't need it anymore
unloadKoinModules(coffeeAppModule)
// Won't resolve CoffeeMaker instance, no more definition
get()<CoffeeMaker>
*
*
*
* // Given a Koin application
val koin = koinApplication {
printLogger()
modules() // no definition
}.koin
// given an instance
val a = ComponentA()
// declare the instance as Single
koin.declare(a)
// can retrieve our ComponentA instance
koin.get<ComponentA>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment