ZenithRef class

A scoped lifecycle handle for a single node's factory context.

Each node created via ZenithContainer.getOrCreateNode or ZenithContainer.getOrCreate receives its own ZenithRef. The ref provides:

  • isMounted — whether the owning container is still alive.
  • set — mounted-safe value writes that silently no-op after disposal.
  • runAsync — mounted-safe async execution with automatic AsyncLoading/AsyncData/AsyncError transitions.
  • onDispose — register teardown callbacks that run when the container is disposed.

All methods that mutate state are guarded by isMounted, so callers never need to manually check lifecycle status after async boundaries.

Available extensions

Constructors

ZenithRef(ZenithContainer container)
Creates a ZenithRef bound to container.

Properties

container → ZenithContainer
The container that owns this ref.
final
hashCode → int
The hash code for this object.
no setterinherited
isMounted → bool
Whether the owning container is still alive.
no setter
logger → ZenithLogger

Available on ZenithRef, provided by the ZenithLoggerRefX extension

Gets the ZenithLogger for this ref's container.
no setter
mediator → ZenithMediator

Available on ZenithRef, provided by the ZenithMediatorRefX extension

Gets the ZenithMediator for this ref's container.
no setter
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
onDispose(void callback()) → void
Registers a callback to run when the owning container is disposed.
onDisposeAsync(Future<void> callback()) → void
Registers awaited resource cleanup. See ZenithContainer.disposeAsync.
read<T>(ZenithNode<T> node) → T
Reads the current value of node.
registerService(ZenithService service) → ZenithServiceRegistration

Available on ZenithRef, provided by the ZenithServiceRefX extension

Starts a service and returns observable lifecycle completion.
runAsync<T>(ZenithNode<AsyncValue<T>> node, Future<T> task()) → Future<void>
Safely runs an async task and writes its result to node, guarding every mutation with this ref's mounted state.
runAsyncGuarded<T>(ZenithNode<AsyncValue<T>> node, Future<T> task(), {ConcurrencyStrategy strategy = ConcurrencyStrategy.restartable}) → Future<void>

Available on ZenithRef, provided by the ZenithConcurrencyX extension

Executes task and writes its result to node, guarding against race conditions between overlapping calls according to strategy.
runInIsolate<T, P>(ZenithNode<AsyncValue<T>> node, P payload, T heavyComputation(P payload), {ConcurrencyStrategy strategy = ConcurrencyStrategy.concurrent}) → Future<void>

Available on ZenithRef, provided by the ZenithIsolateX extension

Runs heavyComputation on a background Isolate via Isolate.run, then writes the result to node via runAsyncGuarded.
runResilient<T>(ZenithNode<AsyncValue<T>> node, Future<T> task(), {required ZenithResiliencePipeline pipeline}) → Future<void>

Available on ZenithRef, provided by the ZenithResilienceRefX extension

Runs task protected by pipeline and writes the state to node.
set<T>(ZenithNode<T> node, T value) → void
Safely sets node to value only if this ref is still mounted.
toString() → String
A string representation of this object.
inherited
watchStream<T>(ZenithNode<AsyncValue<T>> node, Stream<T> stream) → StreamSubscription<T>

Available on ZenithRef, provided by the ZenithStreamX extension

Subscribes to stream and writes each event to node as AsyncData.

Operators

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