ZenithContainer class
A scoped dependency injection container that manages ZenithNodes and their lifecycle.
Nodes are created on-demand via getOrCreateNode (string keys) or
getOrCreate (typed ZenithKeys). Each node receives its own ZenithRef
with lifecycle hooks. When the container is disposed, all refs fire
their onDispose callbacks and all nodes are disposed — preventing memory
leaks and stale state.
Containers support a parent hierarchy for dependency fallback. A child container creates its own independent nodes but can look up missing keys in its parent via maybeReadKey and invalidate.
For testing or feature scoping, pass overrides to replace factory
functions for specific ZenithKeys.
final container = ZenithContainer();
final node = container.getOrCreateNode<int>('counter', (_) => 0);
node.set(1);
container.dispose(); // tears down everything
- Available extensions
Constructors
-
ZenithContainer({ZenithContainer? parent, ZenithEnvironment environment = ZenithEnvironment.production, bool isScopedContainer = false, List<
ZenithOverride> overrides = const [], Map<ZenithEnvironment, List< environmentOverrides = const {}})ZenithOverride> > -
Creates a ZenithContainer, optionally with a
parentfor fallback resolution,overrides, and environment-specificenvironmentOverrides.
Properties
-
disposalComplete
→ Future<
void> -
Completion of asynchronous cleanup initiated by reset/dispose.
no setter
- environment → ZenithEnvironment
-
The active runtime environment for this container.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this container has been disposed.
no setter
- isScopedContainer → bool
-
Whether this container is bound to a scoped (non-singleton) lifetime.
final
- logger → ZenithLogger
-
Available on ZenithContainer, provided by the ZenithLoggerContainerX extension
Gets or creates the ZenithLogger for this container.no setter - mediator → ZenithMediator
-
Available on ZenithContainer, provided by the ZenithMediatorContainerX extension
Gets or creates the ZenithMediator for this container.no setter - parent → ZenithContainer?
-
Optional parent container for hierarchical dependency resolution.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
{bool purgeZeroize = false}) → void -
Disposes this container, firing all
onDisposecallbacks and disposing all managed nodes. -
disposeAsync(
{bool purgeZeroize = false}) → Future< void> - Disposes synchronously, then awaits all registered asynchronous cleanup.
-
getOrCreate<
T> (ZenithKey< T> key, T factory(ZenithRef ref)) → ZenithNode<T> - Type-safe node retrieval or creation using a ZenithKey.
-
getOrCreateNode<
T> (NodeKey key, T factory(ZenithRef ref)) → ZenithNode< T> -
Retrieves or creates a node identified by
key. -
invalidate(
NodeKey key) → void -
Invalidates (re-notifies subscribers of) the node identified by
key. -
invalidateKey<
T> (ZenithKey< T> key) → void - Type-safe convenience wrapper around invalidate for a ZenithKey.
-
maybeNode<
T> (NodeKey key) → ZenithNode< T> ? -
Returns the node for
keyif it exists in this container, ornull. -
maybeReadKey<
T> (ZenithKey< T> key) → ZenithNode<T> ? - Type-safe optional node lookup that also checks parent containers.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
{bool purgeZeroize = false}) → Future< void> - Resets all managed nodes and references in this container without permanently disposing the container itself.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited