Modules, @Provides & @Binds
Tell Hilt how to build your types.
When Constructor Injection Is Not Enough
You cannot add @Inject to a constructor you do not own, like a Retrofit or OkHttp instance. Hilt needs another way to learn how to build those.
Meet the Module
A module is a class that teaches Hilt how to create types it cannot construct on its own. Mark it with @Module to register it.
@Module
object NetworkModule { }All lessons in this course
- Why DI: Testable, Decoupled Code
- Modules, @Provides & @Binds
- hiltViewModel & @HiltViewModel
- Scopes & Component Lifetimes