CompositionContext
Namespace: Hex1b.Composition
Assembly: Hex1b.dll
The hooks-style context passed to . Provides per-instance state storage and an ambient context API for sharing values between a composite and its descendants.
public sealed class CompositionContext : WidgetContext<Hex1bWidget>Inheritance
Object → WidgetContext<Hex1bWidget> → CompositionContext
Properties
CancellationToken
The cancellation token associated with the current reconciliation pass. Composites that perform asynchronous work in Build overrides should observe this token.
Returns: CancellationToken
public CancellationToken CancellationToken { get; }IsNew
True the first time this composite is reconciled (i.e. its node was just created). Use this to perform one-time initialisation against state objects after they are created by .
Returns: Boolean
public bool IsNew { get; }Methods
Provide<T>(T)
Publishes value as ambient context for descendants of this composite. Any descendant within the same subtree can resolve it via or .
Parameters:
value(<T>): The value to publish.
public void Provide<T>(T value) where T : classRequire<T>()
Resolves the nearest ambient value of type T from an ancestor composite, throwing if none has been provided.
Returns: <T>
public T Require<T>() where T : classUse<T>()
Resolves the nearest ambient value of type T from an ancestor composite. Returns null if no ancestor has provided one.
Returns: <T>
public T? Use<T>() where T : classUseState<T>(Func<T>)
Gets or creates a per-instance state object of type T. The factory is invoked once on first call; subsequent calls return the same instance for the lifetime of this composite node.
Parameters:
factory(Func<<T>>): Factory invoked on first access to create the state object.
Returns: <T>
public T UseState<T>(Func<T> factory) where T : classRemarks
A new is constructed on every reconciliation pass, but the underlying composite node persists, so calls to return the same instance across frames.
Every value published with lives on the composite's own node; descendants resolve it by walking the ancestor chain. Use this for ambient values that should flow naturally down a subtree (e.g. theme overrides, form context, controllers).
derives from , so the full fluent widget-building API (ctx.Text(...), ctx.VStack(...), ctx.Button(...), etc.) is available directly inside Build.