Dagger Component has conflicting scopes
我使用的是Dagger,我有一个
[io.droid.nowtellapp.dagger.SignInMvpComponet]
io.droid.nowtellapp.dagger.SignInMvpComponet has conflicting scopes:
io.droid.nowtellapp.dagger.ApplicationComponent also has @Singleton
要解决此错误,我从子comnet中删除了
Error:(12, 1) error: io.droid.nowtellapp.dagger.SignInMvpComponet
(unscoped) may not reference scoped bindings: @Singleton @Provides
io.droid.nowtellapp.mvp.SignInMvp.Presenter
io.droid.nowtellapp.dagger.SignInMvpModule.presenter(io.droid.nowtellapp.webservices.NowTellApi)
也收到此错误:
Error:(21, 8) error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
这是我的ApplicationComponent
1 2 3 4 5 6 7 8 | @Singleton @Component(modules = {AppModule.class, RetroApiModule.class}) public interface ApplicationComponent { void inject(MainActivity mainActivity); SignInMvpComponet signInMvpComponet(SignInMvpModule signInMvpModule); } |
这是我的SignInMvpComponet
1 2 3 | @Subcomponent(modules = {SignInMvpModule.class}) public interface SignInMvpComponet { void inject(SignInFragment signInFragment); |
这是SignInMvpModule类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
如何解决这个问题? 提前致谢。
I have an app component with @Singleton scope and also a subcomponent with @Singleton scope.
不,你不会。 子组件的范围不能与其父组件相同。 您可以阅读文档:
No subcomponent may be associated with the same scope as any ancestor component, although two subcomponents that are not mutually reachable can be associated with the same scope because there is no ambiguity about where to store the scoped objects.
第一个错误是因为父级和子组件共享相同的作用域,第二个错误是因为子组件需要一个作用域。 解决这两个错误的方法是为子组件赋予与父组件不同的范围,或者根本不使用子组件(如果它们都应为
通常,我们倾向于为子组件创建诸如