I’m looking for some good di frameworks for KMP wi...
# multiplatform
d
I’m looking for some good di frameworks for KMP with mobile (android and ios). Anyone have strong preferences for koin vs kotlin-inject?
j
I prefer Koin because it seems to be (to me, at least) the most popular, with the most resources (articles) available. The devs are also active here in #koin (but there's also a #kotlin-inject channel).
☝️ 1
d
Wondering if big google has plans for KMP support with Dagger/Hilt
🚫 1
I like kotlin-inject a lot because it has a better runtime performance, and it’s similar to dagger/hilt
v
The difference in runtime performance is very minute. You won’t even notice the difference.
Until we measure the performance with some metrics, it’s quite hard to say which has better runtime performance
d
I read that in this article, the author had a benchmark with 100 iterations for an example project
👍 3
👍🏻 1
p
kotlin-inject and dagger API are quite the same. I would say kotlin-inject perhaps easier because it is lighter with less concepts. It creates and places the injector bindings in the right place at compilation time, so at runtime is a matter of just calling these bindings, they will give you the dependency. If your App demands high performance, then this is probably the option. Koin in contrast uses a different approach, the factories are created at compilation time but the library locates them in the graph at runtime, and it has a cost. However, the flexibility its API offers, in my opinion is worth this little performance hit. At runtime you can load/unload modules, create/close scopes and such. To me that's gold. Dagger kinda does all that with subcomponents but I like Koin API much more.
j
If you use koin just please make sure you're not using it as a service loader and instead design your classes with proper inversion of control so that you actually are doing DI and gaining its advantages rarher than needlessly coupling your entire application to it.
We use kotlin-inject sparsely, and otherwise just do manual DI. No temptation for junior developers to accidentally do Koin-like service locator coupling
👍 4
😆 2
e
Wow progress 😆
I used Kodein (similar to Koin) for ~6 years on a project that got progressively larger. It started causing some noticeable performance issues on older devices after a while. Never got a chance to dig into what the actual problem was, and no idea if Koin would have similar issues, but I'm very happy with kotlin-inject now. FWIW I was very happy with Kodein as well. We didn't use it as a service locator i.e. it was only used in the graph, all dependencies were injected directly into the classes that required them.