Dagger 2 vs Koin — Quick Look

Anoop M Madasseri
Tech Log
Published in
2 min readMay 29, 2020
Koin 2.0 — A pragmatic lightweight dependency injection framework for Kotlin

Didn’t get a chance to try out Koin. Explored it, and here is the assessment -

Koin is much simpler with cleaner syntax and build completely using the functional resolution (no reflection, no code generation) and makes boilerplate code to a minimum, it has support for ViewModels. Note that It’s is a dependency service locator (DSL), not a dependency injector.

OTOH, Dagger is a fast dependency injector for Java and Android. It’s a compile-time framework. It uses no reflection or runtime bytecode generation, does all its analysis at compile-time, and generates plain Java source code. It’s written in java, a bit tricky learning curve, and causes codebase to grow as it uses annotations which means code generation at compile time.

OK. But Which is Better?

They both do the same thing, and both do it well. If you writing your app in Kotlin know that Dagger is Not a very Kotlin way. Koin is written in pure Kotlin and is really good, especially due to its simplicity and readability.

Nevertheless, Dagger is generating codes at compile time it has better performance than Koin, and Koin is much slower than Dagger in both setup and inject processes.

Choosing between the two depends more on your project scale. Dagger is a great option for large scale applications that doesn’t mean Koin isn’t if you're ready to perceive the slight performance discrepancy!

References

--

--