这是我目前拥有的并且可以正常工作:
@FragmentScope
@Component(dependencies = {FacebookComponent.class},
modules = {FragmentFacebookLoginModule.class})
public interface FragmentFacebookLoginComponent {
void inject(FragmentFacebookLogin fragment);
}
现在,我想添加另一个依赖项。我将其更改为:
@Component(dependencies = {FacebookComponent.class, AnotherComponent.class},
modules = {FragmentFacebookLoginModule.class})
但是现在我收到此错误消息:
FragmentFacebookLoginComponent依赖于多个作用域组件
我该如何解决?我如何有多个依赖关系?
如果我从一个组件中删除范围,则会收到此错误消息:
AnotherComponent(无作用域)不能依赖范围内的组件
我在这里找到了答案:https : //stackoverflow.com/a/29619594/1016472
最后,我创建了具有正确范围的AppComponent,并让FacebookComponent和AnotherComponent扩展了此AppComponent。
FacebookComponent和AnotherComponent没有它自己的范围(我删除了它)。
现在看起来像这样:
@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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句