How to Implement Hilt in Android App?
Dependency injection library is hard to use, this article provides the simple and easy to follow steps to Implement Hilt in your Android app.
Introduction
There are 3 type of dependency injections:
- Manual dependency injection — Inject dependency through constructor parameters
- Service locator — Singleton container that holds the dependencies
- Dependency injection library — Library/framework such as Hilt/Dagger and Koin provide similar functionality as manual dependency injection with less code.
Dependency injection library is hard to use. When I first heard about Hilt/Dagger and Koin, I had no idea what they are about. So I read their documentations and tutorials, it makes my understanding even worst!
My first experience was Koin in my Android Kotlin Developer Nonodegree program. The code is already provided, and I used it without 100% understanding it.
Instead of trying to understand Koin, I came across Hilt which is built on top of Dagger, and it supposes to be a user-friendly. So I gave this a try and I found this useful and simple official tutorial — Using Hilt in your Android app. This tutorial…