registerLazySingleton<T extends Object> abstract method
registers a type as Singleton by passing a factory function that will be called
on the first call of get on that type
T type to register
factoryFunc factory function for this type
instanceName if you provide a value here your factory gets registered with that
name instead of a type. This should only be necessary if you need to register more
than one instance of one type.
onCreated optional callback that will be called after the instance has been created
(when first accessed). This can be useful for logging, analytics, or post-creation setup.
If this callback throws an error, it will be caught and logged but won't prevent
the instance from being created.
registerLazySingleton does not influence allReady however you can wait
for and be dependent on a LazySingleton.
Implementation
void registerLazySingleton<T extends Object>(
FactoryFunc<T> factoryFunc, {
String? instanceName,
DisposingFunc<T>? dispose,
void Function(T instance)? onCreated,
bool useWeakReference = false,
});