Generated modules are global
Is your feature request related to a problem? Please describe.
I'm trying to create many instances of KoinApplication to use in tests that run in parallel. Currently this not possible because the generated module instances are set in global variables.
For example, code like this:
@Module
@ComponentScan("blah")
class ScanModule
Will generate code like this:
public val foo_ScanModule : Module = module {
single() { Blah() }
}
public val ScanModule.module : org.koin.core.module.Module get() = foo_ScanModule
The foo_ScanModule keeps a single global instance of the module, which causes singletons to be shared among all koin instances created with this module.
Describe the solution you'd like
I think calling ScanModule.module should create a new instance of the module each time.
Is it ever necessary to reference the module outside of instantiating Koin/multiple times? If so, couldn't this proposal cause problems? I'm not certain that referencing a module multiple times is ever needed, so this may not actually cause any problems.
I see 2 options for implementing a fix.
- Change the existing
ScanModule.moduleto return a new instance of the module each time. - Keep the current behavior, but allow access to get new instances of the module. Like
ScanModule.createModule()
Either would work for me. With option 1 you can still create and use a global module that would be shared across multiple koin instances, you would just have to do it explicitly.
Ok interesting 🤔 need to check the global impact of this
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
You're breaking my heart stale bot.
duplicated with #102