Singleton class
Annotations for automatic service discovery and registration Used with build_runner for code generation Marks a class as a singleton service The service will be registered once and the same instance returned on each request
Example:
@Singleton()
class DatabaseService {
void connect() { /* ... */ }
}
With custom name:
@Singleton(name: 'primaryDb')
class DatabaseService { /* ... */ }
Properties
-
asType
→ List<
Type> ? -
Optional list of interfaces/abstract classes this service implements
The service will be registered under these types as well
final
- async → bool
-
Whether to register asynchronously
Use when the service needs async initialization
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
Optional name for the service instance
Useful when you have multiple implementations of the same interface
final
- 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