I have question for the 2.1.0 release… what is the...
# koin
a
I have question for the 2.1.0 release… what is the replacement to
GlobalContext.get().koin.inject()
in 2.1.0 for Android? I found
KoinContextHandler.get()
or
getKoin()
that works the same way, but which is expected to be used as replacement?
a
yes exactly 👍
KoinContextHandler
help us specify the kind of context we want. On Android/JVM we have the
GlobalContext
on Kotlin Native and other we are preparing a new context that suits to those platforms
a
So using
KoinContextHandler.get()
is the way to go if I’m using Kotlin for Android?
a
Extension should do the job for you
if you need to the context, yes use it by the KoinContextHandler yes
a
cool and thanks for explanation 🤟
👍 1
m
I’ve just converted my
GlobalContext.get().koin
to
KoinContextHandler.get()
but now I get
No root scoped initialized
exception. Any ideas why?
It looks like it’s because this is being called before
startKoin{}
returns. However, it worked in 2.0.1 My workaround is to move the
loadKoinModules()
calls from within
startKoin{}
to immediately afterwards. Is that the right approach?
a
what do you want to do?
m
Just want to update to 2.1.0 and not have that exception 🙂
a
don’t you use startKoin directly?
m
Within
startKoin{}
I call various
init()
methods (you may remember I mentioned this before) corresponding to different android library modules. An
init()
method will do stuff like
loadKoinModules()
This was working fine in 2.0.1
a
ok then, any problem calling loadKoinModules after starKoin?
m
It seems to be fine - I just wanted to check that it’s an acceptable approach
Also wanted to check there wasn’t an accidental bug introduced in 2.1.0 - perhaps the root scope should be set earlier, for example
a
perhaps the root scope should be set earlier,
when do you have a a problem with roto scope?
m
Could it be that
KoinContextHandler.get().get<X>()
does not work until
startKoin{}
has completed?
a
yes
startKoin is registering the Context for you in KoinContextHandler
m
Ok, I see, thanks. Is it worth noting in change log that
KoinContextHandler.get()
is not exactly the equivalent of
GlobalContext.get().koin
?
a
yes perhaps, make a documentation part on that
I can add in the changelog right now
m
Thanks! Also, I noticed that https://start.insert-koin.io/#/_changelog gives a 404 (accessed from https://start.insert-koin.io/#/ )
a
arf 😕
push in progress, thanks for your feedback 👍
👍 2