Introduction to Dagger 2: For Beginners

Abhinav Singh
7 min readJun 5, 2020

Hello and Welcome, if you are an Android developer or you have just started learning Android you must have heard of Dagger.No it has nothing to do with 🔪 it's a dependency injection framework for both Java and Android. Now you must be wondering what is dependency injection, dependency injection is a programming technique in which one object supplies the dependencies of another object.

Now a question arises as to why we should use dependency injection in our projects what are the advantages? According to the official documentation di provides us with the following advantages:

  • Reusability of code
  • Ease of refactoring
  • Ease of testing

Whatever we are building a clean architecture will always help us. It will save us from writing long boilerplate codes, again and again, it will help us in testing and many more.

Dagger 2 is a compile-time android dependency injection framework and uses the JSR 330 and uses an annotation processor.

In this article, we will learn how to implement dagger 2 in our android projects.

Don’t have a Medium subscription? No worries! Hop on over here to read it for free.

First of all, create a new android studio project and add the following dependencies.

--

--

Abhinav Singh

Software Engineer | Linkedin @cachedengineer | Twitter @cached_engineer