Okay, so I decided to take a closer look on implementing junit tests in my project. Then I stumbled on an article that writes about how important it is to use dependency injection frameworks such as Dagger2 and Koin to ease testing.
I tried to read - What exactly is DI. I understand it as a way of resolving Class A dependant objects (B class and C class, for instance).
What I do right now usually is this:
In Activity I create ViewModel. ViewModel needs to access data, so for data I have SomeRepository class. Then I usually pass SomeRepository through ViewModel constructor or using property injection. As I understand, that is also some type of dependency injection if I'm not mistaken (correct me if I'm wrong).
So, what benefits I'd gain If I'd start using Dagger 2 now? Maybe simple code comparison would make it clearer? Thanks in advance.
Activity:
val someRepository = SomeRepository()
viewModel.init(someRepository)
In ViewModel:
class SomeViewModel : ViewModel {
private lateinit var repository: SomeRepository
fun init(val someRepo: SomeRepository) {
this.repository = someRepo
}
}