Dependency injection (DI) është një pattern ku objektet marrin varësitë e tyre nga jashtë në vend që t'i krijojnë ato — duke përmirësuar testability, maintainability dhe flexibility. Në Android, Hilt (i ndërtuar mbi Dagger) është framework-u i rekomanduar për DI.
Çfarë është DI dhe përse
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).
