AsyncSingleton<T> class
Represents an asynchronously created singleton instance.
It may contain a factory function that returns a Future of the singleton instance. The factory function is invoked only once, and the result is cached for subsequent invocations.
The AsyncSingleton can also specify a list of dependencies that are required for creating the singleton instance. These dependencies can be other types or classes that need to be instantiated before the singleton can be created.
When used on a class, the factory param must point to a static method or a top level function that creates the instance of the singleton.
Example on a class:
@AsyncSingleton(factory: AsyncDemoService.create)
class AsyncDemoService {
static Future<AsyncDemoService> create() async {
return AsyncDemoService();
}
}
Example as a top level function:
@AsyncSingleton()
Future<AsyncFactoryDemoService> createAsyncFactoryDemoService() async {
return AsyncFactoryDemoService();
}
class AsyncFactoryDemoService {}
Constructors
-
AsyncSingleton({Future<
T> factory()?, Iterable<Type> ? dependencies}) -
const
Properties
-
dependencies
→ Iterable<
Type> ? -
final
-
factory
→ Future<
T> Function()? -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited