Emanuel Moecklin
1 min readMay 28, 2021

--

I completely agree with this article. Dagger 2 is way over-engineered and I disagree with Jake Wharton's assessment that a service locator is just for toy apps. Martin Fowler thoroughly compares DI and service locators here: https://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection. I think the gist is that DI is more complex (looking your way Dagger) and that added complexity needs to be justified. Every team, every app and every business is different and Koin is a good (better) choice in more cases than not IMO.

I use Koin for Ktor and love it. For Android I prefer Toothpick, it's even simpler and more concise than Koin:

https://github.com/stephanenicolas/toothpick. Unfortunately it didn't gain much traction so nowadays I would probably pick a different DI framework.

Hilt is a good effort but still over-engineered. What I particularly dislike about Hilt is that it's not platform agnostic. It shines as part of Android but if you decide to use non-standard Android components (e.g. Conductor instead of Fragments) you'll have to jump through some hoops (unlike with platform agnostic frameworks like ... well every other DI framework like Koin, Kodein and Toothpick). There's also a trend to use more generic frameworks over specialized frameworks: cross-platform frameworks (Flutter, React Native), Kotlin multi-platform, GraalVM etc.. Using a tool like Koin supporting multiple platforms (via Kotlin multiplatform) over a tool that supports a single platform (Android) makes imo sense especially if you want an environment that fosters engineers to move between areas instead of breeding the "single-purpose" engineer.

--

--