registerSingletonAsync<T extends Object> abstract method
- FactoryFuncAsync<
T> factoryFunc, { - String? instanceName,
- Iterable<
Type> ? dependsOn, - bool? signalsReady,
- DisposingFunc<
T> ? dispose,
registers a type as Singleton by passing an asynchronous factory function which has to
return the instance that will be returned on each call of get on that type. 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().
factoryFunc
is executed immediately if there are no dependencies to other Singletons
(see below). As soon as it returns, this instance is marked as ready unless you don't
set signalsReady==true
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.
dependsOn
if this instance depends on other registered Singletons before it can be
initialized you can either orchestrate this manually using isReady() or pass a list of
the types that the instance depends on here. factoryFunc
won't get executed till this
types are ready. If signalsReady
is set to true
it means that the future you can get
from allReady()
cannot complete until this instance was signalled ready by calling
signalsReady(instance)
. In that case no automatic ready signal is made after
completion of factoryFunc
Implementation
void registerSingletonAsync<T extends Object>(
FactoryFuncAsync<T> factoryFunc, {
String? instanceName,
Iterable<Type>? dependsOn,
bool? signalsReady,
DisposingFunc<T>? dispose,
});