There are a number of choices out there when it comes to libraries for Android Dependency Injection, but how do you know which is for you?
What is Android Dependency Injection?
According to Wikipedia –
In Android, dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it.
If we want to inject dependencies, we first need to know what a dependency is. In short, a dependency is a coupling between two modules of our code (in oriented object languages, two classes), usually because one of them uses the other to do something.
Comparison of All Android Dependency Injection
When the differences are subtle, it can be helpful to look to the opinions of people who are excited about one solution or another:
TMH Rating – 9.9
ButterKnife is a view binding library that uses annotation to generate boilerplate code for us.It has been developed by Jake Wharton. It makes your code less and more clear. It is time saving to write repetitive lines of code.
See this : How Android Instant Run Works?
To avoid writing repetitive code just like `findViewById(R.id.yourview)`, butterknife helps you to binds fields, method and views for you.
TMH Rating – 9.7
Dagger 2 is dependency injection framework. It is based on the Java Specification Request (JSR) 330. It uses code generation and is based on annotations.
The generated code is very relatively easy to read and debug.
You must see this : Kotlin with Dagger 2 (Dependency Injection)
TMH Rating – 9.5
Google Guice is the framework to automate the dependency injection in applications. It is one of the leading frameworks whose main work is to provide automatic implementation of dependency injection.
Guice aims to make development and debugging easier and faster, not harder and slower. In that vein, Guice steers clear of surprises and magic. You should be able to understand code with or without tools, though tools can make things even easier.
Recommended : Android MVP Pattern Example
When errors do occur, Guice goes the extra mile to generate helpful messages.
TMH Rating – 7.4
Tiger is the fastest! Not faster, but the fastest! I have tried it on a big project with ~200 modules. While it takes hundreds of milliseconds to instantiate dagger components, on the same hardware, it only takes a few milliseconds to instantiate Tiger injectors.
Important for you : Top 20 Daily used Kotlin Code Snippet
Minimal amount of code to write therefore easy to maintain, if you need to maintain it at all. You don’t need to write components like in Dagger.
TMH Rating – 4.6
Toothpick is a scope tree based Dependency Injection (DI) library for Java.
Toothpick is :
- pure java
- fast, it doesn’t use reflection but annotation processing
- simple, flexible, extensible & powerful, robust & tested
- thread safe
- documented & Open Source
- scope safe : it enforces leak free apps
- test oriented : it makes tests easier
- it works very well with Android or any other context based framework (such as web containers)
TMH Rating – 4.5
KOIN is a Kotlin dependency injection framework that and its functional power to get things done! No proxy/CGLib, No code generation, No introspection. Just functional Kotlin and DSL magic 😉
It is an open source project to help you write your dependency injection in few lines.
TMH Rating – 2.5
ActivityStarter is an Android Library that provides simpler way to start the Activities with multiple arguments.
Did you use this : How to Use Springy Facebook Rebound?
Library bindes fields to Actity, Fragment, Service or Receiver arguments and generates simple starters. Thanks to that you can:
- Eliminate all putExtra and getXXXExtra methods
- Forget about all keys that were used to pass arguments (unless you want to define custom onces)
- Start liking starting flags and intent creation
So after reading above article you can easily classified and find which dependency injection is better for you next Android project.
And please let me know if you’ve any other Dependency Injection library which you want to add in this list. 😉😉