I’m in the process of migrating to 4.0, and notice...
# koin
m
I’m in the process of migrating to 4.0, and noticed there is a new startup dependency. Since I’m already using androidx-startup I decided to see how this works. The example talks about putting the new
onKoinStartup
in the Application subclass’ init block. However, apps that use androidx-startup often don’t declare an Application subclass because all logic has been moved in the startup
Initializer
implementations. Also, in my current startup logic, I call
startKoin
and then make use of the
KoinApplication
returned from that class (passing it to various gradle modules). So what is the proper way to get
KoinApplication
after migrating away from
startKoin
?
The second part mentioned in the OP, is important because of
createEagerInstances
which is called after
startKoin
and using the
KoinApplication
returned by
startKoin
. I suppose the solution is to just use
GlobalContext.get().createEagerInstances()
instead?
I was able to get
onKoinStartup
working by creating an
Application
subclass and then calling it there from an
init
block (as suggested by the docs). I’d also tried doing this from within
Initializer.onCreate(Context)
but couldn’t get that to work because the Koin initializer was being invoked beforehand. It would be nice if there was some way to do all this within androidx startup initializers.
a
Hey @Mark thanks for the feedback, yes use of init block is not so good in the end. there is a thread around that here: https://kotlinlang.slack.com/archives/CRF31N2HW/p1727741805144049
👍 1