SimplestServiceLocator class final

Implements ISimplestServiceLocator to provide a service locator with singleton, lazy singleton, and factory capabilities.

Constructors

SimplestServiceLocator.instance()
Returns the singleton instance of SimplestServiceLocator. Creates a new instance if none exists.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Clears all registered services.
get<T extends Object>({String? name}) → T
Retrieves a service of type T. If the service is not found, throws ServiceNotRegisteredException.
getAsync<T extends Object>({String? name}) Future<T>
Retrieves a service of type T asynchronously. If the service is not found, throws ServiceNotRegisteredException.
isRegistered<T extends Object>({String? name}) bool
Determines whether a service of type T is already registered. Returns true if the service is registered, false otherwise.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerFactory<T extends Object>(T factory(), {String? name}) → void
Registers a factory for creating new instances of the service T. Each call to get will invoke the provided factory to create a new instance.
registerFactoryAsync<T extends Object>(Future<T> asyncFactory(), {String? name}) → void
Registers a factory for creating new instances of the service T asynchronously. Each call to getAsync will invoke the provided asyncFactory to create a new instance.
registerLazySingleton<T extends Object>(T factory(), {String? name}) → void
Registers a lazy singleton service of type T. The service is created upon the first call to get and reused thereafter. The factory provides the method to create the service.
registerLazySingletonAsync<T extends Object>(Future<T> asyncFactory(), {String? name}) → void
Registers a lazy singleton service of type T that is created asynchronously. The service is created upon the first call to getAsync and reused thereafter. The asyncFactory provides the method to create the service asynchronously.
registerSingleton<T extends Object>(T instance, {String? name}) → void
Registers a singleton service of type T with an instance. Throws ServiceAlreadyRegisteredException if a service of type T is already registered.
toString() String
A string representation of this object.
inherited
unregister<T extends Object>({String? name}) bool
Unregisters a service of type T. Returns true if the service was successfully unregistered, false if it wasn't registered.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

reset() → void
Resets the singleton instance of SimplestServiceLocator. This is particularly useful for testing.