package com.github.hunter0x7c7.sync.app;
|
|
|
import com.github.hunter0x7c7.sync.model.data.source.cache.CacheDataSourceImpl;
|
import com.github.hunter0x7c7.sync.model.data.source.local.LocalDataSourceImpl;
|
import com.github.hunter0x7c7.sync.model.server.ServiceApi;
|
import com.github.hunter0x7c7.sync.model.data.MainRepository;
|
import com.github.hunter0x7c7.sync.model.data.source.CacheDataSource;
|
import com.github.hunter0x7c7.sync.model.data.source.HttpDataSource;
|
import com.github.hunter0x7c7.sync.model.data.source.LocalDataSource;
|
import com.github.hunter0x7c7.sync.model.data.source.http.HttpDataSourceImpl;
|
import com.github.hunter0x7c7.sync.model.server.ServiceClient;
|
|
/**
|
* ================================================================
|
* <p>
|
* 版 权: Hunter(c)2020
|
* <p>
|
* 作 者: Hunter
|
* <p>
|
* 版 本: V1.0
|
* <p>
|
* 创建日期: 2020/7/30 16:15
|
* <p>
|
* 描 述:注入全局的数据仓库,可以考虑使用Dagger2。(根据项目实际情况搭建,千万不要为了架构而架构)
|
* <p>
|
* <p>
|
* 修订历史:
|
* <p>
|
* ================================================================
|
*/
|
public class Injection {
|
|
|
public static MainRepository provideMainRepository() {
|
//网络API服务
|
ServiceApi apiService = ServiceClient.getInstance().provideServiceApi();
|
//网络数据源
|
HttpDataSource httpDataSource = HttpDataSourceImpl.getInstance(apiService);
|
//本地数据源
|
LocalDataSource localDataSource = LocalDataSourceImpl.getInstance();
|
//缓存数据源
|
CacheDataSource cacheDataSource = CacheDataSourceImpl.getInstance();
|
//两条分支组成一个数据仓库
|
return MainRepository.getInstance(httpDataSource, localDataSource, cacheDataSource);
|
}
|
|
}
|