Dagger2 为什么不能将一种类型注入到多个组件中?

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

在 Dagger2 中,是否可以从多个组件请求相同的 class 注入。下面的示例代码

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

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

如果可能,请解释原因和任何文档参考。

谢谢

不是同时。您可以调用任意一个注入函数,但不能先用 compA 再用 compB 注入它。但是,您可以创建一个基于子组件 A 和 B 的组件 C,然后将其注入。