Idiomatic Android Architecture Components with Koin

Vaygeth (Abdulmohsen)
2 min readMay 6, 2018

This post aims to focus on demonstrating the use of Architecture Components with Koin dependency injection in simple & idiomatic way.

https://insert-koin.io/ & https://github.com/Ekito/koin

Why this post?

As Android developer, I always avoid stacking up huge dependencies and libraries in any of my development projects, because I noticed myself struggling setting up and debugging the errors of these libraries rather than focusing on developing & delivering the project. This happens often when I’m new to certain frameworks, therefore I only absolutely use them when I estimate this will be the beneficial approach for my use-cases. Common practices in Android community is often follows the approach of employing Dagger 2 for dependency injection. Dagger 2 approach is often discouraging for new learners (and me when I started learning Dagger 2 concepts). So in this code samples I implemented a simple way to handle Android Architecture Components in Kotlin with support of Koin dependency injection.

More reason I prefer Koin over Dagger 2?

As clarified in previous section that I always intend to minimize complex libraries or advanced techniques where it can be achieved in cleaner & simplistic approach, Koin offers that in place of Dagger 2 by doing the full implementation using Kotlin code without annotation or framework constraint. Unlike Koin, Dagger 2 heavily uses annotations and abstractions which makes code implementations complex and neither intuitive (at least in my opinion) by creating many interfaces & abstract classes for small projects.

What does the app do?

It’s a Company app that displays all it’s employees names with their age in a recycle-view list, where you can add one employee into database or delete the whole employees records on database via floating action buttons.

https://github.com/vaygeth89/Android-ArchitectureCompKoin-Company

--

--

Vaygeth (Abdulmohsen)

I’m a software developer & UI/UX designer who want to share my experience with fellow developers. abdulmohsen.co https://www.patreon.com/vaygeth