iammert / dagger-android-injection

Sample project explains Dependency Injection in Android using dagger-android framework.
515 stars 130 forks source link

Where does dagger2 get mainvView? #2

Closed ysmintor closed 7 years ago

ysmintor commented 7 years ago
 @Provides
 MainPresenter provideMainPresenter(MainView mainView, ApiService apiService){
 return new MainPresenterImpl(mainView, apiService);
 }

I don't find any Inject of mainView, Where could Dagger2 to find it and then to provide MainPresenter?

ysmintor commented 7 years ago

Also I want to ask about the how to Inject specific Retrofit2 like a different base url in that Activity to provide, So How could Dagger2 solve this problem?

iammert commented 7 years ago

@ysmintor When you inject into your activity, your activity will be attached to your dagger graph. Then you can provide your mainView with your activity. Actually, It is already defined in MainActivityModule

ysmintor commented 7 years ago

@iammert After a while I saw the code in MainPresenterImpl.


   @Inject
   public MainPresenterImpl(MainView mainView, ApiService apiService) {
   this.mainView = mainView;
   this.apiService = apiService;
   }

So for the mainView, I have to add a MainViewImpl and add @Inject above its contructor to let Dagger2 inject?

iammert commented 7 years ago

Yes. I suggest you read https://google.github.io/dagger/ .