123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import 'package:domain/constants/api_constants.dart';
- import 'package:domain/repository/auth_repository.dart';
- import 'package:domain/repository/job_repository.dart';
- import 'package:domain/repository/job_sg_repository.dart';
- import 'package:domain/repository/labour_repository.dart';
- import 'package:domain/repository/labour_sg_repository.dart';
- import 'package:domain/repository/other_repository.dart';
- import 'package:plugin_basic/basic_export.dart';
- import 'package:plugin_basic/dio_interceptors/interceptor_auth_dio.dart';
- import 'package:plugin_basic/dio_interceptors/interceptor_status_code_dio.dart';
- import 'package:plugin_basic/service/http_provider_injection.dart';
- import 'package:plugin_basic/service/user_service.dart';
- import 'package:plugin_platform/http/http_provider.dart';
- import 'package:shared/utils/log_utils.dart';
- /*
- 全局服务 Service 的初始化入口
- 1. 默认注入网络请求Provider与Domain的Repository
- 2. 留下高阶函数的入口,方便加入其他的全局服务
- 全局单例服务的注入,在 main.dart 入口就可直接调用,注意手动调用
- */
- class GlobalServicesInjection {
- /// init
- static void init({void Function()? additionalDependencies}) {
- Log.d('----ConfigServicesInjection------start-----');
- //全局单例的 HttpProvider 用于发起网络请求 (根据不同的选择国家注入不同的域名)
- HttpProviderInjection.putHttpProviderByCountry();
- //全局单例的用户数据仓库
- Get.put(AuthRepository(httpProvider: Get.find()));
- //其他的数据仓库注入
- Get.lazyPut(() => JobRepository(httpProvider: Get.find()));
- Get.lazyPut(() => JobSGRepository(httpProvider: Get.find()));
- Get.lazyPut(() => LabourRepository(httpProvider: Get.find()));
- Get.lazyPut(() => LabourSGRepository(httpProvider: Get.find()));
- Get.lazyPut(() => OtherRepository(httpProvider: Get.find()));
- // 用户信息服务(用户信息相关业务类)
- Get.put(UserService(Get.find()));
- // 调用额外的依赖注入逻辑(如果提供了)
- if (additionalDependencies != null) {
- additionalDependencies();
- }
- Log.d('----ConfigServicesInjection------end-----');
- }
- }
|