123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:router/componentRouter/auth_service.dart';
- import 'package:router/componentRouter/profile_service.dart';
- import 'package:router/componentRouter/rewards_service.dart';
- import '../ext/router_provider_container.dart';
- import 'app_service.dart';
- import 'community_service.dart';
- import 'facility_service.dart';
- import 'form_service.dart';
- import 'main_service.dart';
- import 'notice_board_service.dart';
- import 'payment_service.dart';
- import 'property_service.dart';
- import 'service_service.dart';
- class ComponentServiceManager {
- // 私有构造函数
- ComponentServiceManager._internal();
- // 单例实例
- static final ComponentServiceManager _instance = ComponentServiceManager._internal();
- factory ComponentServiceManager() {
- return _instance;
- }
- // 存储 `ServiceProvider` 的 Map
- final Map<Type, Provider> _serviceProviders = {};
- // 添加 `ServiceProvider` 的方法
- void addServiceProvider<T>(Provider<T> provider) {
- _serviceProviders[T] = provider;
- }
- // 获取 `MainService` 的方法
- MainService get mainService {
- final provider = _serviceProviders[MainService];
- if (provider == null) {
- throw Exception('Provider for MainService not found.');
- }
- return routerContainer.read(provider as Provider<MainService>);
- }
- AppService get appService {
- final provider = _serviceProviders[AppService];
- if (provider == null) {
- throw Exception('Provider for AppService not found.');
- }
- return routerContainer.read(provider as Provider<AppService>);
- }
- ProfileService get profileService {
- final provider = _serviceProviders[ProfileService];
- if (provider == null) {
- throw Exception('Provider for ProfileService not found.');
- }
- return routerContainer.read(provider as Provider<ProfileService>);
- }
- AuthService get authService {
- final provider = _serviceProviders[AuthService];
- if (provider == null) {
- throw Exception('Provider for AuthService not found.');
- }
- return routerContainer.read(provider as Provider<AuthService>);
- }
- CommunityService get communityService {
- final provider = _serviceProviders[CommunityService];
- if (provider == null) {
- throw Exception('Provider for CommunityService not found.');
- }
- return routerContainer.read(provider as Provider<CommunityService>);
- }
- FacilityService get facilityService {
- final provider = _serviceProviders[FacilityService];
- if (provider == null) {
- throw Exception('Provider for FacilityService not found.');
- }
- return routerContainer.read(provider as Provider<FacilityService>);
- }
- FormService get formService {
- final provider = _serviceProviders[FormService];
- if (provider == null) {
- throw Exception('Provider for FormService not found.');
- }
- return routerContainer.read(provider as Provider<FormService>);
- }
- NoticeBoardService get noticeBoardService {
- final provider = _serviceProviders[NoticeBoardService];
- if (provider == null) {
- throw Exception('Provider for NoticeBoardService not found.');
- }
- return routerContainer.read(provider as Provider<NoticeBoardService>);
- }
- PaymentService get paymentService {
- final provider = _serviceProviders[PaymentService];
- if (provider == null) {
- throw Exception('Provider for PaymentService not found.');
- }
- return routerContainer.read(provider as Provider<PaymentService>);
- }
- PropertyService get propertyService {
- final provider = _serviceProviders[PropertyService];
- if (provider == null) {
- throw Exception('Provider for PropertyService not found.');
- }
- return routerContainer.read(provider as Provider<PropertyService>);
- }
- RewardsService get rewardsService {
- final provider = _serviceProviders[RewardsService];
- if (provider == null) {
- throw Exception('Provider for RewardsService not found.');
- }
- return routerContainer.read(provider as Provider<RewardsService>);
- }
- ServiceService get servicesService {
- final provider = _serviceProviders[ServiceService];
- if (provider == null) {
- throw Exception('Provider for ServiceService not found.');
- }
- return routerContainer.read(provider as Provider<ServiceService>);
- }
- }
|