Android/Koin - How to tell koin that a single dependency should be reinitialized

Viewed 2215

I stumbled across a problem where I have to reinitialize my Retrofit API class because the URL changes, so I want to tell Koin to reinitialize the single dependency. I don't want to use factory because it is still a singleton most of the time.

Stopping and starting koin would be an idea but that is a very heavy and time intense prozess so I don't want to do that.

any ideas?

1 Answers

After doing A LOT OF RESEARCH, I found this post on GitHub scoping is the solution for my problem.

--- OR ---

using

unloadKoinModules(networkModule)
loadKoinModules(networkModule)

and then get the instance again:

val api: InstanceApi = getKoin().get()
Related