I understood so. If you need to pass parameters to the method that will be injected, then you need to make another method that will provide this parameter to Dagger .
That's what there is
@Module class ModelModule { @Provides @Singleton ApiInterface provideApiInterface() { return ApiModule.getApiInterface(); } } A method that works great. Now, if we need to add a parameter to this method, then we immediately need to create a method that will provide this parameter
like this
@Module class ModelModule { @Provides @Singleton int provideInt() { return 1; } @Provides @Singleton ApiInterface provideApiInterface(int i) { return ApiModule.getApiInterface(i); } } But the thing is that I already have another module in which the method with the return type int initialized
@Module class AnotherModule { @Provides Integer getInt(){ return 3; } } And it turns out that when I start, I get this error
Error: (11, 10) error: java.lang.Integer is bound multiple times: @Provides @ Singleton int com.krokosha.aleksey.daggertwo.ModelModule.provideInt () @Provides Integer com.krokosha.aleksey.daggertwo.AnotherModule. getInt ()
It turns out I can not use 2 methods that return the same type ... But how then to be?
I need him both there and there ...
@Singletondocumentation, because this annotation clearly indicates the presence of only one instance in the container. - etkiintshould not roll? As for sington, I tried to delete these annotations, but still the same error ... Can you give an example of how this code should look like? - Aleksey Timoshchenko