Dependency injection (DI) என்பது ஒரு pattern ஆகும், இதில் objects தங்கள் dependencies களை தாங்களே உருவாக்குவதற்குப் பதிலாக வெளியிலிருந்து பெறுகின்றன — testability, maintainability, மற்றும் flexibility ஆகியவற்றை மேம்படுத்துகின்றன. Android-ல், Hilt (Dagger-ன் மீது கட்டப்பட்டது) பரிந்துரைக்கப்பட்ட DI framework ஆகும்.
DI என்றால் என்ன மற்றும் ஏன்
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).
