Container class
A hierarchical Dependency Injection (DI) container.
The Container supports singletons, factories, and scoped instances. It can be nested to create isolated scopes (e.g., per-request).
- Available extensions
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- parent → Container?
-
The parent container to delegate to if a service is not found locally.
final
- queue → Queue
-
Available on Container, provided by the QueueContainerExtensions extension
Retrieves the registered Queue instance.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
child(
) → Container - Creates a child container that delegates to this one for missing services.
-
dispose(
) → Future< void> - Disposes of all locally registered instances that implement Disposable.
-
factory<
T> (T factory(Container), {String? name}) → void -
Registers a
factorythat will be executed every time resolve is called. -
has<
T> ({String? name}) → bool -
Returns
trueif a service of typeTis registered. -
instance<
T> (T instance, {String? name}) → void -
Registers an
instancelocally in this container. -
lazySingleton<
T> (T factory(Container), {String? name}) → void -
Registers a
factorythat will be executed once and its result stored as a singleton. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerInstance<
T> (T instance, {String? name}) → void -
Registers an
instancelocally in this container. Alias forinstance. -
resolve<
T> ({String? name}) → T -
Resolves an instance of type
T. -
scoped<
T> (T factory(Container), {String? name}) → void -
Registers a
factorythat will be executed once per container scope (e.g. per request). -
singleton<
T> (T instance, {String? name}) → void -
Registers a
instanceas a singleton available globally (or at this container's level). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited