(无作用域)不能依赖于dagger2中的作用域组件

时间:2018-12-16 04:36:20

标签: android dagger-2

这是我的Fragment dagger2组件:

@PreMainFrag
@Component(modules = {MainFragModule.class},
        dependencies = AppComponent.class)
public interface MainFragComponent {
        void inject(MainFragment mainFragment);
}

这是MainFragModule:

@Module
public class MainFragModule {

    MainFragment mainFragment;

    public MainFragModule(MainFragment mainFragment) {
        this.mainFragment = mainFragment;
    }

    @Provides
    @PreMainFrag
    MainFragment getMainFragment(){
        return mainFragment;
    }

}

但是当我想用匕首时,我得到了这个错误:

symbol:   class DaggerAppComponent
  location: package com.t.stm.application.di
E:\Projects\Android\Stm\Stm\stm\src\main\java\com\t\stm\mainFragment\main\di\MainFragComponent.java:9: error: com.t.stm.mainFragment.main.di.MainFragComponent (unscoped) cannot depend on scoped components:
@Component(modules = {MainFragModule.class},
^
      @com.t.stm.application.di.AppScope com.t.stm.application.di.AppComponent
2 errors
:stm:compileDebugJavaWithJavac FAILED

这是怎么回事?我在组件上添加了@PreMainFrag

这是我的作用域类:

@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface PreMainFrag {
}

****************************编辑******************** ***********

这是AppComponent:

@AppScope
@Component(modules = {NetworkModule.class,
        AppRetroServiceModule.class,
        MainRepositoryModule.class})
public interface AppComponent {

    Gson getGson();

    APIService getService();

    @AppQualifierHttpClientThread
    APIService getServiceWithThread();

    MainRepository getMainRepository();

}

及其应用范围:

@Scope
@Retention(RetentionPolicy.CLASS)
public @interface AppScope {
}

我也将@Retention(RetentionPolicy.CLASS)更改为@Retention(RetentionPolicy.RUNTIME),但没有任何改变。

当我从dependencies = AppComponent.class中删除MainFragComponent时,一切都很好,我可以做匕首,但是依赖性问题是什么?

0 个答案:

没有答案