Dependency Injection with Dagger, Hilt, and Koin
This chapter covers the concept of dependency injection and the benefits it provides to an Android application. We will look at how we can perform dependency injection manually with the help of container classes. We will also cover some of the frameworks available for Android, Java, and Kotlin that can help developers when it comes to applying this concept. By the end of this chapter, you will be able to use Dagger 2 and Koin to manage your app’s dependencies and know how to organize them efficiently.
In the previous chapter, we looked at how to structure code into different components, including ViewModels, API components, and persistence components. One of the difficulties that always emerged was the dependencies between all of these components, especially when it came to how we approached the unit tests for them.
We will cover the following topics in this chapter:
- Manual DI
- Dagger 2
- Hilt
- Koin