koin-annotations
koin-annotations copied to clipboard
Support KSP-generated module to be used in multiple KoinApplication instances
I believe KSP should generate:
public val package_name_ModuleName : Module get() = module {
// ... module internals ...
}
instead of
public val package_name_ModuleName : Module = module {
// ... module internals ...
}
Currently creating two separated KoinApplications with module generated by KSP in the same runtime gives the same beans instead of different instances.
Example of difference:
val fooModule: Module get() = module { single<Foo>() { Foo() } }
val koinApp1 = koinApplication { modules(fooModule) }
val koinApp2 = koinApplication { modules(fooModule) }
val beanFromKoinApp1 = koinApp1.koin.get<Foo>()
val beanFromKoinApp2 = koinApp1.koin.get<Foo>()
//beanFromKoinApp1 and beanFromKoinApp2 are different instances
val fooModule: Module = module { single<Foo>() { Foo() } }
val koinApp1 = koinApplication { modules(fooModule) }
val koinApp2 = koinApplication { modules(fooModule) }
val beanFromKoinApp1 = koinApp1.koin.get<Foo>()
val beanFromKoinApp2 = koinApp1.koin.get<Foo>()
//beanFromKoinApp1 and beanFromKoinApp2 are the same instance
Yes, the current implementation is unfortunately, global. See #92 and #102.
Let's continue on those #92 #102. Next milestones should fix that soon