Dependency injection (DI) is a technique widely used in programming and well suited to Android development. By following the principles of DI, you lay the groundwork for a good app architecture.
Implementing dependency injection provides you with the following advantages:
Reusability of code.
Ease of refactoring.
Ease of testing.
I have always seen Dependency injection (DI) with Dagger2 as the big Elephant in the room, I made a decision to address this elephant once and for all. I found it easier starting off with Dagger Implementation in Java, then Dagger in Kotlin and finally the new google recommended DI for Android Hilt in Kotlin
I found a very useful blog by CodingFlow which gave me a very good lift off, very simple,clear and awesome implementation.
- Dagger 2 in Java CodingFlow Dagger2 Tutorials
After grasping the whole concept of Dagger in Java it was time to jump into my favorite train of Kotlin. For Kotlin google have a very awesome documentation and a codelab. I took the codeLab
To implement hilt I had two approach,