createAtStart should also work when loadKoinModules() is called
See original GitHub issueIs your feature request related to a problem? Please describe.
In our application we create a bare-bones KoinApplication that knows just enough to assess and setup a local environment to get it into a stable, well known state. Once in that known state, then more modules are loaded, based on the conditions of what happened in the assessment/setup phase. It looks like this:
val bootstrapModule = module {
single { AAA(get()) }
single { BBB() }
single(createdAtStart = true) { CCC(get()) }
}
startKoin {
modules(bootstrapModule)
}
val moduleDDD = buildDDDModule( ... using AAA, BBB or CCC ... )
val moduleEEE = module {
single(createdAtStart = true) { ZZZ() }
}
val moduleFFF = module { ... }
loadKoinModules(listOf(
moduleDDD,
moduleEEE,
moduleFFF
))
The problem is that ZZZ
does not get created when loadKoinModules
is called. When ZZZ
is something that we want to “fail fast”, we won’t know there is a problem until it gets instantiated later.
Describe the solution you’d like
The desired behavior is to have loadKoinModules()
honor the createAtStart
flag. The meaning of createAtStart
would perfectly fit with the intent.
Describe alternatives you’ve considered
The current workaround is to place some dummy code that calls upon ZZZ
early in the application.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
added
createEagerInstances
parameter toloadModules
function, in Koin 2.2.0Can you please give me an example for Android?
I’m trying this way, but it’s an internal function
getKoin().createEagerInstances()
I have seen that KoinApplication has the createEagerInstances method as public, but I couldn’t find a way to get the current KoinApplication instance!
Thanks.