registerLazySingletonAsync<T extends Object> abstract method
registers a type as Singleton by passing an async factory function that will be called
on the first call of getAsync on that type
This is a rather esoteric requirement so you should seldom have the need to use it.
This factory function factoryFunc isn't called immediately but wait till the first call by
getAsync() or isReady() is made
To control if an async Singleton has completed its factoryFunc gets a Completer passed
as parameter that has to be completed to signal that this instance is ready.
Therefore you have to ensure that the instance is ready before you use get on it or use
getAsync() to wait for the completion.
You can wait/check if the instance is ready by using isReady() and isReadySync().
instanceName if you provide a value here your instance 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.
registerLazySingletonAsync does not influence allReady however you can wait
for and be dependent on a LazySingleton.
Implementation
void registerLazySingletonAsync<T extends Object>(
FactoryFuncAsync<T> factoryFunc, {
String? instanceName,
DisposingFunc<T>? dispose,
void Function(T instance)? onCreated,
bool useWeakReference = false,
});