Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i copy some code of your project ,but has catch: contains a dependency cycle #29

Open
sungerk opened this issue May 14, 2016 · 0 comments

Comments

@sungerk
Copy link

sungerk commented May 14, 2016

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));
    }

}
@sungerk sungerk changed the title i copy some code of yout project ,but has catch: contains a dependency cycle i copy some code of your project ,but has catch: contains a dependency cycle May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant