[英]Android/Koin - How to tell koin that a single dependency should be reinitialized
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 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.
我不想使用工厂,因为大多数时候它仍然是 singleton。
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.停止和启动 koin 将是一个想法,但这是一个非常繁重且时间密集的过程,所以我不想这样做。
any ideas?有任何想法吗?
After doing A LOT OF RESEARCH, I found this post on GitHub scoping is the solution for my problem.经过大量研究后,我发现这篇关于GitHub范围界定的帖子是我的问题的解决方案。
--- OR --- ---或者---
using使用
unloadKoinModules(networkModule)
loadKoinModules(networkModule)
and then get the instance again:然后再次获取实例:
val api: InstanceApi = getKoin().get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.