Why using kodein is beneficial rather than using k...
# multiplatform
v
Why using kodein is beneficial rather than using koin in KMM project?
k
I’m not sure one has killer features over the other. I think they’re both pretty common in KMM, but I haven’t really done a big feature compare in years, so can’t speculate on recent developments.
c
The big difference that comes to mind is that Koin doesn’t support multibindings, and doesn’t look like there are any plans to add it since the issue requesting it was closed without actually being implemented. Kodein does support multibindings, and generally offers many more features than Koin, but Koin is intended to be a more lightweight option. Personally, I find the Koin DSL to be cleaner and easier to read, but I’ve really struggled to get it to work well with any use-case it doesn’t explicitly support. I find the scoping API confusing, and you can’t really define a hierarchy of injectors like you would with Dagger. I haven’t used Kodein all that much, but I personally would choose Kodein over Koin the next time I need a KMM service locator. Kotlin-inject is another option I’ve got my eye on, which is basically a reimplementation of Dagger in KSP
k
Have you used kotlin-inject? We’ve got an open research project internally to evaluate these other options, but nobody seems too excited to hop on it 🙂 I’m very curious, though.
c
I haven’t used it yet, I only just saw it for the first time a few days ago
e
I've used it in some POCs. So far happy with most of it, and I'm going to continue building with it until/unless I discover any showstoppers.
k
Hmm, thanks. I find evaluating those kinds of libraries tough because I’m not what you’d call a “DI aficionado”. I’ve found a certain % of developers really get into the weeds with that stuff, then everybody else is like “it compiles? Great…” I haven’t found anybody on the team who’s a “DI aficionado”, so I don’t know. Maybe we’ll just try it out on something.
c
I tend to use hand-written DI for most of my projects until I find a need that makes it overly cumbersome without some kind of proper tool. I’ve definitely worked on projects large enough to need it for cleanliness, or where I need to swap out dependencies for different build variants or different parts of the application. Multibindings is one of the features of DI I find very important in modular applications, that is difficult to do in hand-written DI, as is hierarchical injectors for providing different instances to different portions of the app.