Weaver class

The main dependency injection container for Weaver.

Weaver manages the registration, retrieval, and lifecycle of dependency objects. It supports global registrations, named dependencies, sessions, and scopes.

You can observe changes in registrations by adding an observer using addObserver.

Implementers

Constructors

Weaver()
Creates a new Weaver instance.

Properties

allowReassignment bool
Whether to allow reassigning registered dependencies and scope handlers.
getter/setter pair
allowScopesWithoutHandler bool
Whether to allow calling enterScope with a scope that has no registered ScopeHandler.
getter/setter pair
handlers Iterable<ScopeHandler>
no setter
hashCode int
The hash code for this object.
no setterinherited
named WeaverNamed
Type-safe access to named dependencies generated by weaver_builder.
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scopes Iterable<Scope>
The currently active scopes in this Weaver instance.
no setter

Methods

addObserver(Function observer) → void
inherited
addScopeHandler(ScopeHandler newHandler) Future<void>
Adds a ScopeHandler to this Weaver instance.
clearSession(String session) → void
Removes all dependency objects registered under the given session name.
enterScope(Scope scope) Future<void>
Signals that the application has entered the given scope.
get<T extends Object>({String? name}) → T
Retrieves a registered dependency of type T (and optionally name).
getAsync<T extends Object>({String? name}) Future<T>
Asynchronously retrieves a registered dependency of type T (and optionally name).
isInScope(String scopeName) bool
Returns true if the Weaver has entered the scope with the given scopeName.
isRegistered<T extends Object>({Type? type, String? name}) bool
Returns true if a dependency of type T (and optionally name) is registered.
leaveScope(String scopeName) Future<void>
Signals that the application has left the scope with the given scopeName.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyObservers() → void
inherited
register<T extends Object>(T instance, {String? name, String? session}) → void
Registers a dependency instance of type T.
registerIfAbsent<T extends Object>(T instance, {String? name, String? session}) → void
Registers instance only if nothing is already registered for the same type and optional name.
registerIfIsNot<T extends Object>(T instance, {String? name, String? session}) → void
Use registerIfAbsent instead.
registerLazy<T extends Object>(T callback(), {String? name}) → void
Registers a lazy dependency that will be instantiated when first requested.
removeObserver(Function observer) → void
inherited
removeScopeHandler(String scopeName) Future<void>
Removes the ScopeHandler that handles the scope with scopeName.
reset() → void
Clears all registered dependencies, active scopes, and scope handlers.
toString() String
A string representation of this object.
inherited
unregister<T extends Object>({Type? type, String? name}) → void
Unregisters a dependency object by its type T or name.

Operators

operator ==(Object other) bool
The equality operator.
inherited