Why DI: Testable, Decoupled Code
See the problems Hilt solves.
What Is Dependency Injection?
Dependency injection means a class receives the objects it needs from the outside, instead of building them itself. Less wiring, more focus. 🔌
The Problem: new Everywhere
When a class calls new on its own dependencies, it gets locked to those exact types. Changing one thing forces you to edit many files.
class Repo {
private val api = ApiService() // hard-wired
}All lessons in this course
- Why DI: Testable, Decoupled Code
- Modules, @Provides & @Binds
- hiltViewModel & @HiltViewModel
- Scopes & Component Lifetimes