Modules and Providers
Tell Hilt how to create dependencies.
Telling Hilt How to Build Things
Hilt can construct a class automatically if its constructor is annotated @Inject. But for interfaces or types you do not own, you must teach Hilt with a Module.
Constructor Injection
The simplest case: annotate the constructor and Hilt knows how to build it.
class Analytics @Inject constructor(
private val api: ApiService
)All lessons in this course
- Why Dependency Injection?
- Setting Up Hilt
- Modules and Providers
- Injecting into ViewModels