Heh, I opened this chat to ask if there's a proper...
# multiplatform
d
Heh, I opened this chat to ask if there's a proper DI library for KMP which is not a Service Locator implementation, and here is the survey about missing libraries. Still. Is there a non-SL DI library available for KMP?
k
do you need it to support concurrency?
k
Not that I’m aware of. What comparable libraries would you be looking for?
k
here is the most "authoritative" list of libraries I have come across: https://github.com/AAkira/Kotlin-Multiplatform-Libraries
d
Not that I’m aware of. What comparable libraries would you be looking for?
I guess it would be Dagger/Toothpick. Maybe Guice, but it uses reflection which is slow on Android.
do you need it to support concurrency?
Not only that. To provide dependencies in general, this is crucial for large apps...
k
none of the current DI/SL libraries support native concurrency last I checked
i rolled my own barebones impl.
k
So, no. I’m working with Koin lead on native, obviously with concurrency support, but that’s not “proper”, so no, there are no options as of now.
We’re using the Koin version now for our stuff: https://github.com/touchlab/KaMPKit. Hopefully we’ll have a version out with 1.3.70, but we’ll see
d
Got it! I mentioned this in the survey posted above :)
I had an experience with Kodein, so I thought to try it, it seem to have KMP support already.
none of the current DI/SL libraries support native concurrency last I checked
You mean accessing dependencies from other threads? Issues with freezing?
k
It does not really support native threading, unless the situation has changed.
Yes
He means that
d
I see. Can I work around that by creating classes on the main thread?
k
The Koin version I’m working on would support that, although you’d need to explicitly let other threads inject. I want to avoid silently freezing if possible
Yeah, that’s the goal of what I’m working on with the Koin version. All DI is main thread, and you can keep state mutable
If you need to move it to another thread, it’s frozen
Description in readme (not exactly a full description, but you get the idea): https://github.com/kpgalligan/koin/tree/kpg/kmp_update
d
Great, thank you!
k
I’m guessing there will be a serious release soon. I want to push more of an experimental one in the next week or so (“experimental” in that we also want to allow JVM to work as it currently does, optionally, but the experimental one will just be main-thread only)
👏 1
k
I managed to get SL using
by inject()
without having in injected object frozen
k
With Kodein? If yes, my issue is, as of last time I looked at it, if you happened to capture something from kodein or access it from another thread, it would (in theory) freeze the kodein config, which would silently cause issues. Maybe not a huge deal sometimes, but you’ll eventually have issues. I think it should be explicit, and I also want Android to behave the same. So, the Koin version I’m working on will throw the same exceptions if you try to access it from other threads.
k
no, my own
kodein just crashed
k
Yeah, I mean people use it. Not trashing on it. I just think the thread awareness needs to be explicit
However, I’m a little fixated on the concurrency topic
d
I support explicitness too. I've used Toothpick DI library (jvm) and they went with ConcurrentHashMaps internally, but I never needed this thread safety in my apps, so maybe I could avoid paying performance price for this. Although, of course, I didn't notice any slowdown, so it's not fair judgement, but I still think sometimes it could be lighter.