Dagger 2 for Dummies in Kotlin (with 20 lines of code)

--

Note: This article is a 10 minute fun read. If you prefer a quicker and shorter tutorial, check out the 4 minute version of Even Simpler Dagger 2 Tutorial

I am a dummy, and learning Dagger 2 is stretching my brain! The tutorials I read introduced so many topics at once e.g. Dependency Injection, Provider, Component, Module, Scope… my brain just exploded!

Besides many of the tutorials are based on Java. Kotlin is the way of doing things today. It took me months to digest Dagger 2 and integrate it with Kotlin. So I vowed to myself that when I understand it, I will create something really super simple, like the ABCs of Dagger 2, for those out there like me looking for a basic introduction.

To help me do so, I create what I believe as the world’s simplest Android App with Dagger 2… Just one page, less than 20 lines 😎 (please don’t make another simpler one, let me keep one world record 😝).

Many tutorial shows pages after pages of codes, and linking relationships between classes. My brains hurts… as my stack is shallow 😝

(For the experts, I apologize for the very unconventional way of introducing Dagger 2, as this is really for dummies.)

Let’s go to (very) basic programming (… in Android)

--

--