How would I create an instance of Dog with a component which provides Cat.
public final class Dog {
private final Ca
To create an object using the Dagger 2 constructor injection feature you need to add a method to a component which provides a Cat class.
@Component(
dependencies = ApplicationComponent.class,
modules = CatModule.class)
public interface ActivityComponent {
void inject(final CatActivity a);
// objects exposed to sub-components
Cat cat();
Dog dog();
}
An instance of Dog can then be retrived by calling [Component].dog()
.
final ActivityComponent comp = DaggerActivityComponent.builder()
.applicationComponent(app.getApplicationComponent())
.build();
final Dog d = comp.dog();