Injectarea dependențelor (DI) este un pattern în care obiectele primesc dependențele lor din exterior în loc să le creeze — îmbunătățind testabilitatea, mentenabilitatea și flexibilitatea. În Android, Hilt (construit pe Dagger) este framework-ul DI recomandat.
Ce este DI și de ce contează
WITHOUT DI: a class CREATES its own dependencies (tightly coupled, hard to test/change):
class UserRepo { val api = ApiService() } // creates its own dependency — rigid
WITH DI: dependencies are PROVIDED from outside (injected):
class UserRepo(val api: ApiService) // receives it → flexible, testable
→ Benefits: TESTABILITY (inject mocks/fakes in tests), DECOUPLING, easier to swap
implementations, centralized dependency management, less boilerplate (with a framework).
