Skip to content

contains a dependency cycle #377

@sungerk

Description

@sungerk
Error:(23, 20) 错误: org.sunger.net.injector.components.AppComponent.getRestDataSource() contains a dependency cycle:
org.sunger.net.injector.modules.AppModule.provideDataRepository(org.net.sunger.mode.model.RestDataSource restDataSource)
[parameter: org.net.sunger.mode.model.RestDataSource `restDataSource]
@Module                                                                                         
public final class AppModule {                                                                  

    private final MsApplication mAvengersApplication;                                           

    public AppModule(MsApplication avengersApplication) {                                       
        this.mAvengersApplication = avengersApplication;                                        
    }                                                                                           

    @Provides                                                                                   
    @Singleton                                                                                  
    MsApplication provideAvengersAppContext() {                                                 
        return mAvengersApplication;                                                            
    }                                                                                           

    @Provides                                                                                   
    @Named("executor_thread")                                                                   
    Scheduler provideExecutorThread() {                                                         
        return Schedulers.newThread();                                                          
    }                                                                                           

    @Provides                                                                                   
    @Named("ui_thread")                                                                         
    Scheduler provideUiThread() {                                                               
        return AndroidSchedulers.mainThread();                                                  
    }                                                                                           

    @Provides                                                                                   
    File provideCacheFile(){                                                                    
        return FileUtils.createDirs(ConfigConstants.RX_CACHE_DIR);                              
    }                                                                                           

    @Provides                                                                                   
    MsAuthorizer provideMsAuthorizer() {                                                        
        MsAuthorizer msAuthorizer = new MsAuthorizer();                                         
        OauthUserEntity userEntity = mAvengersApplication.getOauthUserEntity();                 
        if (userEntity != null) {                                                               
            msAuthorizer.setAccessToken(userEntity.getAccess_token());                          
        }                                                                                       
        return msAuthorizer;                                                                    
    }                                                                                           

    @Provides @Singleton                                                                        
    RestDataSource provideDataRepository(RestDataSource restDataSource) {                       
        return restDataSource;                                                                  
    }                                                                                           
}                                                                                               
                                                                                                `
@Singleton
@Component(modules = AppModule.class)
public interface AppComponent {
    MsApplication application();
    RestDataSource getRestDataSource();

    MsAuthorizer msAuthorizer();

    File getCacheDir();

    @Named("ui_thread")
    Scheduler uiThread();
    @Named("executor_thread") Scheduler executorThread();

}
public class RestDataSource {
    private static final int CONNECT_TIMEOUT_MILLIS = 30;
    private static final int READ_TIMEOUT_MILLIS = 30;
    private final CacheProviders cacheProviders;
    private RestApiService restApi;


    @Inject
    public RestDataSource(File cacheDir, MsAuthorizer msAuthorizer) {
        cacheProviders = new RxCache.Builder()
                .persistence(cacheDir)
                .using(CacheProviders.class);
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder().
                connectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.SECONDS).
                readTimeout(READ_TIMEOUT_MILLIS, TimeUnit.SECONDS).addInterceptor(new MsInterceptor(msAuthorizer.getAccessToken())).
                addInterceptor(httpLoggingInterceptor).build();
        Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL).
                client(okHttpClient).
                addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
                addConverterFactory(GsonConverterFactory.create()).build();
        restApi =retrofit.create(RestApiService.class);
    }

    public Observable<Reply<List<CategoryEntity>>> getCategory(final boolean update) {
        return cacheProviders.getCategory(restApi.getCategory(), new EvictProvider(update));
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions