Repository navigation
Conversation
…g, not non-empty mappings Signed-off-by: Inf1mum <vadim.lazuk@mail.ru>
|
Friendly reminder - open to review whenever convenient, and happy to make any needed changes. |
| saveMapping(override, mapping, factory) | ||
|
|
||
| } | ||
| module.isLoadedFlag = true |
There was a problem hiding this comment.
What happens when a module is unloaded via unloadKoinModules(...) / InstanceRegistry.unloadModules(...)? unloadModule() doesn't reset module.isLoadedFlag = false, so module.isLoaded stays true even after its definitions have been removed from _instances.
There was a problem hiding this comment.
Good catch - you are right that unloadModules left isLoadedFlag untouched, so isLoaded stayed true after unloading. The unload path now resets the flag to false (mirroring the true set on load), so isLoaded reflects actual loading end to end, and the definitions are dropped from _instances as before. A regression test covers the load -> unload -> isLoaded == false flow, including the included-module case, and fails on the previous head without the fix.
…ed reflects actual state Signed-off-by: Inf1mum <vadim.lazuk@mail.ru>
Fixes #2373
Problem
Module.isLoadedwas implemented asmappings.isNotEmpty(). Sincemappingsis populated as soon as definitions are declared through the DSL (before any registry involvement),isLoadedreturnedtruefor any non-empty module, even beforestartKoin/loadKoinModules:Fix
isLoadednow reflects the actual module loading:Modulekeeps an internal@KoinInternalApi internal var isLoadedFlag(defaultfalse), and the public getter returns that flag — the public ABI is unchanged (public final fun isLoaded ()Z).InstanceRegistry.loadModule(...)setsmodule.isLoadedFlag = trueonce the module's mappings have been saved into the instance registry. This covers bothstartKoin { modules(...) }andloadKoinModules(...), as well as modules pulled in viaincludes(...)(loading goes throughflatten, so included modules are marked too).Semantic change (heads-up)
isLoadedused to mean "this module declares at least one definition". It now means "this module has actually been loaded into an instance registry". Concretely:false(this was the bug);true(the flag tracks "was loaded", not "has definitions").Design note / question for maintainers
The flag is currently not reset on
unloadModules/close(): it staystrueonce the module has been loaded at least once ("was loaded at some point" semantics). If the preferred semantics are "currently loaded in the registry", the flag could be cleared inInstanceRegistry.unloadModule(...)instead — happy to adjust.