Hunter0x7c7
2023-08-12 0b0ca05018a5f47a1c8b1573e0eff4310ebca1a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
    }
 
}