Whoa! Wait? What the heck is Dependency Injection? We know most of you are gonna ask this question. Hence be sure to watch this video first that attempts to answer what is dependency, what is injection, why do you need it, what would you do without it and how it changes things.
What is Dependency Injection?
So, now that you understand a bit about DI in general, let’s take a look at some dependency injection libraries in Android. The simplest of them would be ButterKnife. Lets take a look at how to use ButterKnife in our apps with a simple example.
Android ButterKnife Dependency Injection
What is ButterKnife?
The code for our ButterKnife demo is available right HERE.
A slightly more sophisticated library to handle dependency injection is Roboguice in Android. Let’s take a look at how to use Roboguice in our android apps.
Android Roboguice Dependency Injection
What is Roboguice
The code for our Roboguice demo is available right HERE. Don’t forget to notice that Roboguice demo has 2 branches, one of them contains code prior to adding Roboguice and the other one contains code after adding it.
What about Android Annotations and Dagger 2?
In the PREVIOUS post, we talked about what is dependency injection, and how to implement it with ButterKnife and Dagger 2. In this post, we dive deeper and talk about 2 sophisticated libraries for implementing DI in Android.
Android Annotations Dependency Injection
What is it?
The code for Android Annotations demo is available right HERE. Don’t forget that it has 2 branches, one of them contains code before adding the library and the other one contains code after modifying everything.
Last, but not the least, we cover the most sophisticated DI library in Android.
Android Dagger 2 Dependency Injection
What is it?
The code for Dagger 2 demo is available right HERE. Don’t forget that it has 2 branches, one of them contains code before adding the library and the other one contains code after modifying everything. So hopefully you understood something about how dependency injection can be implemented in Android after watching all the videos. If yes, don’t forget to rate us 5 stars HERE and let us know what your thoughts in the comments below. Happy learning 🙂