11

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?

kaulex
  • 2,921
  • 3
  • 11
  • 38
  • why don't you create 2 instances with 2 different base urls? – Rinat Diushenov Aug 11 '20 at 17:51
  • The problem is that this case can happen more often then 2 times so I would need to create a new retrofit instance every time I use it. SO I thought about solving it in koin, to recreate only one single dependency – kaulex Aug 16 '20 at 10:52

1 Answers1

12

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()
kaulex
  • 2,921
  • 3
  • 11
  • 38
  • But the isuue author wrote about a leak. Do you consider that? – ivan8m8 Sep 16 '21 at 12:10
  • I just mentioned the issue because it is providing the solution. It is not the same issue I had. Never had problems with the solution here. – kaulex Sep 17 '21 at 07:51