Implementing DI with Hilt
DI libraries are often used to simplify and accelerate the incorporation of DI in our projects, especially when the infrastructure code required by manual DI gets difficult to manage in large projects.
Hilt is a DI library that is part of Jetpack, and it removes the unnecessary boilerplate involved in manual dependency injection in Android apps by generating the code and the infrastructure that you otherwise would have had to develop manually.
Note
Hilt is a DI library based on another popular DI framework called Dagger, meaning that they are strongly related, so we will often refer to Hilt as Dagger Hilt in this chapter. Due to the steep learning curve of the Dagger APIs, Hilt was developed as an abstraction layer over Dagger to allow easier adoption of automated DI in Android projects.
Dagger Hilt relies on annotation processors to automatically generate code at build time, making it able to create and optimize the process of managing and providing...