addLazySingleton<T extends Object> static method
void
addLazySingleton<T extends Object>(
- T factory()
Registers a dependency as a Lazy Singleton.
The instance will only be created the first time it is requested
and then kept in cache for subsequent calls.
Throws an IonLocatorDuplicateRegistrationException if the type is already registered.
Implementation
static void addLazySingleton<T extends Object>(T Function() factory) {
if (_factories.containsKey(T)) {
throw IonLocatorDuplicateRegistrationException(T);
}
_factories[T] = () {
if (!_singletons.containsKey(T)) {
_singletons[T] = factory();
}
return _singletons[T]!;
};
}