Skip to content

Instantly share code, notes, and snippets.

@qwert2603
Last active August 7, 2021 17:03
Show Gist options
  • Save qwert2603/427fba5cee19a96c0bbf51935e43143f to your computer and use it in GitHub Desktop.
Save qwert2603/427fba5cee19a96c0bbf51935e43143f to your computer and use it in GitHub Desktop.
fun main() {
val koin = startKoin {
val module1 = module {
declareMultibinding<String, Int>()
intoMultibinding("one", 1)
intoMultibinding("two", 2)
intoMultibinding("three", 3)
declareMultibinding<String, Double>()
intoMultibinding("one", 1.0)
}
val module2 = module {
intoMultibinding("six", 6)
intoMultibinding("seven", 7.0)
declareMultibinding<Float, Unit>()
intoMultibinding(3.14f, Unit)
}
modules(module1, module2)
}.koin
println(koin.getMultibinding<String, Int>()) // {one=1, two=2, six=6, three=3}
println(koin.getMultibinding<String, Double>()) // {seven=7.0, one=1.0}
println(koin.getMultibinding<Float, Unit>()) // {3.14=kotlin.Unit}
val module3 = module {
intoMultibinding("seven", 7)
}
koin.loadModules(listOf(module3))
println(koin.getMultibinding<String, Int>()) // {one=1, two=2, six=6, three=3, seven=7}
koin.unloadModules(listOf(module3))
println(koin.getMultibinding<String, Int>()) // {one=1, two=2, six=6, three=3}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment