I’m in the process of upgrading from 3.0.1 to 3.1....
# koin
m
I’m in the process of upgrading from 3.0.1 to 3.1.1, and am getting runtime errors due to
single(createdAtStart = true)
being started more eagerly than in 3.0.1. Now it seems that such declarations are immediately invoked. Is this working as intended (i.e. 3.0.1 was faulty) or a bug in 3.1.1?
a
created directly at the module level, instead of waiting Koin start?
m
The crash happens before any of the definitions are loaded. When I add a breakpoint just before the component is instantiated, here is the difference in stacktrace: Koin3.0.1 (at this point, the startKoin lambda has already been executed)
Copy code
create:54, InstanceFactory (org.koin.core.instance)
create:40, SingleInstanceFactory (org.koin.core.instance)
invoke:48, SingleInstanceFactory$get$1 (org.koin.core.instance)
invoke:26, SingleInstanceFactory$get$1 (org.koin.core.instance)
synchronized:20, KoinPlatformTools (<http://org.koin.mp|org.koin.mp>)
get:46, SingleInstanceFactory (org.koin.core.instance)
createEagerInstances$koin_core:118, InstanceRegistry (org.koin.core.registry)
createEagerInstances$koin_core:271, Scope (org.koin.core.scope)
createEagerInstances$koin_core:196, Koin (org.koin.core)
createEagerInstances:114, KoinApplication (org.koin.core)
startKoin:66, GlobalContext (org.koin.core.context)
Koin3.1.1
Copy code
create:53, InstanceFactory (org.koin.core.instance)
create:46, SingleInstanceFactory (org.koin.core.instance)
invoke:53, SingleInstanceFactory$get$1 (org.koin.core.instance)
invoke:51, SingleInstanceFactory$get$1 (org.koin.core.instance)
synchronized:20, KoinPlatformTools (<http://org.koin.mp|org.koin.mp>)
get:51, SingleInstanceFactory (org.koin.core.instance)
createEagerInstances:82, InstanceRegistry (org.koin.core.registry)
loadModules$koin_core:46, InstanceRegistry (org.koin.core.registry)
loadModules:326, Koin (org.koin.core)
loadModules:80, KoinApplication (org.koin.core)
access$loadModules:31, KoinApplication (org.koin.core)
invoke:60, KoinApplication$modules$duration$1 (org.koin.core)
invoke:59, KoinApplication$modules$duration$1 (org.koin.core)
measureDuration:38, MeasureKt (org.koin.core.time)
modules:59, KoinApplication (org.koin.core)
onStartKoin:128, MyApplicationBase (<http://foo.bar.app|foo.bar.app>)
onStartKoin:32, MyApplication (<http://foo.bar.app|foo.bar.app>)
invoke:113, MyApplicationBase$onCreate$1 (<http://foo.bar.app|foo.bar.app>)
invoke:108, MyApplicationBase$onCreate$1 (<http://foo.bar.app|foo.bar.app>)
startKoin:64, GlobalContext (org.koin.core.context)
a
Yep, eager instances are created when declaring modules within startKoin in 3.1.1
👍 1
in 3.0.1 it was seperated ok, I see
1
it crashes in your case because you don’t have all your dependencies?
m
Ok thanks. My app is multi-module and some library modules use beans declared (single) in the app module (Application subclass). Other beans are declared in library modules and used in app module. So now (with 3.1.1) I’ve changed things around so that the Application subclass first declares beans used by library modules, then calls library modules to declare their own beans, and then finally declares it’s own beans (which may make use of beans from library modules). Seems to work!
a
Perhaps not the best way to run eagrInstances in 3.1.1, I was writing a small fix for 3.1.2 to run all eager isntances just after the module load phase