Manual DI
In order to understand how DI works, we can first analyze how we can manually inject dependencies into different objects across an Android application. This can be achieved by creating container objects that will contain the dependencies required across the app. You can also create multiple containers representing different scopes that are required across the application. Here, you can define dependencies that will only be required as long as a particular screen is displayed, and when the screen is destroyed, the instances can also be garbage collected.
A sample of a container that will hold instances as long as an application lives is shown here:
class AppContainer(applicationContext:Context) { val myRepository: MyRepository init { val retrofit = Retrofit.Builder().baseUrl("https://google.com/").build() ...