I saw the following example on the Dagger 2 website:
class Thermosiphon implements Pump {
private final Heater heater;
@Inject
Thermosiphon(Heater he
For one, since you've annotated the constructor of Thermosiphon
with @Inject
, you don't need an @Provides
method. Dagger uses this constructor to create an instance when needed. Just annotate the Thermosiphon
class itself with @Singleton
to preserve the singleton behavior.
If you do want to use an @Provides
method, and to answer your question fully, you can specify the Heater
as a parameter to the method:
@Module
public class ThermosiphonModule {
@Provides
@Singleton
Thermosiphon provideThermosiphon(Heater heater) {
return new Thermosiphon(heater);
}
}