Dependency Injection with Kodein & MVVM Architecture – Android Kotlin Tutorial
Not a single software developer ever said that a more loosely coupled code gives him headaches. On the contrary, tight coupling can and will create a bunch of things that are hard to deal with.
But first, what is that “loose coupling”? Loose coupling means not instantiating dependencies of a class directly but getting them from a centralized place. Dependencies are simply classes which are needed by other classes. For example, a view model needs a repository, so the repository is a dependency of the view model.
Loose coupling also means that your classes operate with their dependencies through an interface and not directly with their concrete implementation. This allows you to swap implementations really easily. For example, a production implementation of a database will store data on a remote server, while a test implementation will store data only locally.
In this tutorial you are going to learn how to put what’s written above into practice by using a dependency injection framework called Kodein. It is specifically designed to work well with Kotlin and it’s also compatible with Java.