I want to start using dagger 2 for my side project I am working on.
An android application using MVVM design pattern. I use Dagger 2 as a dependency injection tool. It does the job but generally I need a lot of injections inside my (Models). The only way I found to do the job is to have an static instance of Application class that I do once I create it.
So I can inject it on the Model layer, where I do not have activity or application context. I am wondering is this the correct way of doing it or I am wrong?
//Inside Application class
private static Context context;
public static Context getContext() {
return context;
}
//Inside Model class
((MainApplication)MainApplication.getContext()).getMyComponent().inject(this);