Good day.
Faced a problem when upgrading to Dagger2 version 2.11 and higher with Moxy. I have a presenter from Moxie, to which I need to pass the API. There is no possibility to inject this with Api, since in Dagger, starting with version 2.10, use the AndroidSupportInjection.inject(this); method AndroidSupportInjection.inject(this); to get dependencies can only Activity / Fragment. Therefore, this Api needs to be passed to the prezer through its constructor. The problem is that this presenter has no constructor in the fragment, since Inject itself as follows:
@InjectPresenter(type = PresenterType.WEAK) public WeatherPresenter weatherPresenter; Fortunately, Moxy has the ability to add @ProvidePresenter annotation and add input parameters:
@Inject @ProvidePresenter(type = PresenterType.WEAK) WeatherPresenter provideWeatherPresenter(WeatherApi weatherApi) { return new WeatherPresenter(weatherApi); } However, another problem appears, apparently, Dagger does not recognize the above described piece of code, so this is the error:
Error: (24, 20) error: method provideWeatherPresenter in class BaseFragment cannot be applied to given types; required: WeatherApi found in length
Tell me, can someone come across such a problem? Is it possible to somehow "throw" Api into a presenter using a pair of Moxy + Dagger 2.10+ or use Dagger in the old way?
@Providesmethod of one of thedaggermodules. After that you will be able to inject the presenter via the@Inject Provider<PresenterClassName> provider, and from the annotated@ProvidePresenterreturn theprovider.get()YuriySPb ♦@ProvidePresenterdoes not accept parameters, but in the module itself you can use the previously "injected" API - ivanovd422