You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
/// Service locator for dependency injection.
|
|
///
|
|
/// Provides a centralized registry for all application services,
|
|
/// making it easy to access services throughout the app
|
|
/// and swap implementations for testing.
|
|
class ServiceLocator {
|
|
/// Private constructor to prevent instantiation.
|
|
ServiceLocator._();
|
|
|
|
/// Singleton instance.
|
|
static final ServiceLocator instance = ServiceLocator._();
|
|
|
|
/// Local storage service.
|
|
dynamic _localStorageService;
|
|
|
|
/// Nostr service.
|
|
dynamic _nostrService;
|
|
|
|
/// Sync engine.
|
|
dynamic _syncEngine;
|
|
|
|
/// Firebase service.
|
|
dynamic _firebaseService;
|
|
|
|
/// Session service.
|
|
dynamic _sessionService;
|
|
|
|
/// Immich service.
|
|
dynamic _immichService;
|
|
|
|
/// Recipe service.
|
|
dynamic _recipeService;
|
|
|
|
/// Theme notifier.
|
|
dynamic _themeNotifier;
|
|
|
|
/// Registers all services with the locator.
|
|
///
|
|
/// All services are optional and can be null if not configured.
|
|
void registerServices({
|
|
dynamic localStorageService,
|
|
dynamic nostrService,
|
|
dynamic syncEngine,
|
|
dynamic firebaseService,
|
|
dynamic sessionService,
|
|
dynamic immichService,
|
|
dynamic recipeService,
|
|
dynamic themeNotifier,
|
|
}) {
|
|
_localStorageService = localStorageService;
|
|
_nostrService = nostrService;
|
|
_syncEngine = syncEngine;
|
|
_firebaseService = firebaseService;
|
|
_sessionService = sessionService;
|
|
_immichService = immichService;
|
|
_recipeService = recipeService;
|
|
_themeNotifier = themeNotifier;
|
|
}
|
|
|
|
/// Gets the local storage service.
|
|
///
|
|
/// Throws [StateError] if service is not registered.
|
|
dynamic get localStorageService {
|
|
if (_localStorageService == null) {
|
|
throw StateError('LocalStorageService not registered');
|
|
}
|
|
return _localStorageService;
|
|
}
|
|
|
|
/// Gets the Nostr service (nullable).
|
|
dynamic get nostrService => _nostrService;
|
|
|
|
/// Gets the sync engine (nullable).
|
|
dynamic get syncEngine => _syncEngine;
|
|
|
|
/// Gets the Firebase service (nullable).
|
|
dynamic get firebaseService => _firebaseService;
|
|
|
|
/// Gets the session service (nullable).
|
|
dynamic get sessionService => _sessionService;
|
|
|
|
/// Gets the Immich service (nullable).
|
|
dynamic get immichService => _immichService;
|
|
|
|
/// Gets the Recipe service (nullable).
|
|
dynamic get recipeService => _recipeService;
|
|
|
|
/// Gets the Theme notifier (nullable).
|
|
dynamic get themeNotifier => _themeNotifier;
|
|
|
|
/// Clears all registered services (useful for testing).
|
|
void reset() {
|
|
_localStorageService = null;
|
|
_nostrService = null;
|
|
_syncEngine = null;
|
|
_firebaseService = null;
|
|
_sessionService = null;
|
|
_immichService = null;
|
|
_recipeService = null;
|
|
_themeNotifier = null;
|
|
}
|
|
}
|
|
|