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 _serviceProviders = {}; // 添加 `ServiceProvider` 的方法 void addServiceProvider(Provider 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); } AppService get appService { final provider = _serviceProviders[AppService]; if (provider == null) { throw Exception('Provider for AppService not found.'); } return routerContainer.read(provider as Provider); } ProfileService get profileService { final provider = _serviceProviders[ProfileService]; if (provider == null) { throw Exception('Provider for ProfileService not found.'); } return routerContainer.read(provider as Provider); } AuthService get authService { final provider = _serviceProviders[AuthService]; if (provider == null) { throw Exception('Provider for AuthService not found.'); } return routerContainer.read(provider as Provider); } CommunityService get communityService { final provider = _serviceProviders[CommunityService]; if (provider == null) { throw Exception('Provider for CommunityService not found.'); } return routerContainer.read(provider as Provider); } FacilityService get facilityService { final provider = _serviceProviders[FacilityService]; if (provider == null) { throw Exception('Provider for FacilityService not found.'); } return routerContainer.read(provider as Provider); } FormService get formService { final provider = _serviceProviders[FormService]; if (provider == null) { throw Exception('Provider for FormService not found.'); } return routerContainer.read(provider as Provider); } NoticeBoardService get noticeBoardService { final provider = _serviceProviders[NoticeBoardService]; if (provider == null) { throw Exception('Provider for NoticeBoardService not found.'); } return routerContainer.read(provider as Provider); } PaymentService get paymentService { final provider = _serviceProviders[PaymentService]; if (provider == null) { throw Exception('Provider for PaymentService not found.'); } return routerContainer.read(provider as Provider); } PropertyService get propertyService { final provider = _serviceProviders[PropertyService]; if (provider == null) { throw Exception('Provider for PropertyService not found.'); } return routerContainer.read(provider as Provider); } RewardsService get rewardsService { final provider = _serviceProviders[RewardsService]; if (provider == null) { throw Exception('Provider for RewardsService not found.'); } return routerContainer.read(provider as Provider); } ServiceService get servicesService { final provider = _serviceProviders[ServiceService]; if (provider == null) { throw Exception('Provider for ServiceService not found.'); } return routerContainer.read(provider as Provider); } }