Dependency injection in Android

Gabriel Tanner
AndroidPub
Published in
5 min readMar 4, 2019

--

Photo by Luca Bravo on Unsplash

Today, we are going to discuss in-depth about dependency injection in Android and why you should be using it.

Definitions and advantages

Dependency injection is a technique where objects are created by an external entity or object. This means an object doesn’t have to create the instances of its dependent classes on his own but rather gets the dependencies from another object or static method.

This technique has many benefits here I’m just listing the most important ones:

  • Reduces the boilerplate code
  • Makes our code reusable and clean
  • Makes it easy to replace our dependencies with fake implementations which make testing easier
  • Helps us enable loose coupling

Now that we know about the basic concepts of dependency injection we will take a look at the different solutions and frameworks for dependency injection in Android.

Kodein

Kodein is a very simple and yet very useful dependency framework which is easy to configure and use. It’s easy to learn and provides some great benefits, with the most important being:

  • It proposes a very simple and readable declarative DSL
  • It handles dependency…

--

--

Gabriel Tanner
AndroidPub

Android Developer | Web Developer | Part-time Blogger | Catch me at https://gabrieltanner.org/ | Buy me a coffee buymeacoff.ee/gabrieltanner