eC Droid
eC Droid

Reputation: 681

Dagger2 Why can't one type is injected into more than one component?

In Dagger2 is it possible to request same class for injection from more than one component. Sample code below

@Component(modules = classA.class)
interface compA
{
void inject(MyActivity target);
}

@Component(modules = classB.class)
interface compB
{
void inject(MyActivity target);
}

If possible please explain with reason and any doc reference.

Thanks

Upvotes: 0

Views: 77

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93561

Not at the same time. You can call either inject function you wish on it, but you can't inject it with compA then compB. You could however make a componentC that builds off of subcomponents A and B and inject it with that.

Upvotes: 1

Related Questions