https://kotlinlang.org logo
#koin
Title
# koin
j

janvladimirmostert

07/30/2022, 8:07 PM
Out of curiosity, when I call
Copy code
single { Repository(get(named("remote")),get(named("local")))
where is that Repository instance actually stored? and when I call
Copy code
val repo : Reposity by inject
where is that instance being pulled from again? is there any interesting magic happening here or is it literally keeping that instance in something like a hashmap?
s

Stylianos Gakis

07/30/2022, 9:36 PM
Looking into the sources it seems like for non scoped modules, they are added here which happens in the loadModules which is what’s called from your normal
startKoin { modules(listOf(myModules…))}
then this is inside InstanceRegistry. Then to resolve it does this, so in short yeah it seems to be in a
safeHashMap
which is of type
MutableMap
which implementation is different depending on the actual platform Kotlin is being compiled for, a java.util.concurrent.ConcurrentHashMap for jvm so also Android as I understand.
j

janvladimirmostert

07/30/2022, 10:20 PM
ah yes, I forgot about concurrency, although I never thought that concurrency is actually an issue for setting up the DI types. Probably somewhere out there, somebody is doing something strange with the library that required this or since this is a library, it's better to be safe than getting a ConcurrentModificationException
3 Views