Why Dependency Injection?
Make code testable and modular.
What Is Dependency Injection?
Dependency Injection (DI) means giving an object the things it needs from the outside, rather than letting it create them itself.
The Problem: Hard Dependencies
When a class builds its own dependencies, it becomes tightly coupled and hard to change or test.
class UserViewModel {
private val repo = UserRepository(
ApiClient(), AppDatabase.get()
) // tightly coupled
}All lessons in this course
- Why Dependency Injection?
- Setting Up Hilt
- Modules and Providers
- Injecting into ViewModels