Priklausomybių injekcija (DI) yra šablonas, kai objektai gauna savo priklausomybes iš išorės, o ne jas patys kuria — tai pagerina testavimą, priežiūrą ir lankstumą. Android-e Hilt (paremtas Dagger) yra rekomenduojama DI sistema.
Kas yra DI ir kodėl jis svarbus
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).
