问题描述
这是我目前所拥有的并且有效:
This is what I currently have and it works:
@FragmentScope
@Component(dependencies = {FacebookComponent.class},
modules = {FragmentFacebookLoginModule.class})
public interface FragmentFacebookLoginComponent {
void inject(FragmentFacebookLogin fragment);
}
现在我想添加另一个依赖项。我把它更改为:
Now I want to add another dependency. I changed it to this:
@Component(dependencies = {FacebookComponent.class, AnotherComponent.class},
modules = {FragmentFacebookLoginModule.class})
但现在我收到此错误消息:
But now I get this error message:
我该如何解决这个问题?我如何拥有多个依赖项?
How can I solve this? How can I have more than one dependencies?
如果我从一个组件中删除范围,我会收到以下错误消息:
If I remove the scope from one component I get this error message:
推荐答案
https://stackoverflow.com/a/29619594/1016472
最后,我创建了一个具有正确范围的AppComponent,让FacebookComponent和AnotherComponent扩展这个AppComponent。
At the end I created a AppComponent with the right scope and let FacebookComponent and AnotherComponent extends this AppComponent.
FacebookComponent和AnotherComponent没有拥有它自己的范围(我将其删除)。
FacebookComponent and AnotherComponent does not have it's own scope (I removed it).
现在看起来像这样:
@AppScope
@Component
public interface AppComponent {
}
@Component(modules = {FacebookModule.class})
public interface FacebookComponent extends AppComponent {
}
@Component(modules = {AnotherModule.class})
public interface AnotherComponent extends AppComponent {
}
@FragmentScope
@Component(dependencies = {FacebookComponent.class, AnotherComponent.class},
modules = {FragmentFacebookLoginModule.class})
public interface FragmentFacebookLoginComponent {
void inject(FragmentFacebookLogin fragment);
}
这篇关于具有多个依赖项的Dagger2组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!