Avengers
Avengers copied to clipboard
i copy some code of your project ,but has catch: contains a dependency cycle
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));
}
}