Open sandboxFocus

Struct InitializationContext

A context passed to constructors and Initialize(InitializationContext) methods to coordinate post-initialization behavior. Carries the caller's intent, aspect behavior slots, and optional metadata.

Namespace: Metalama.Framework.RunTime.Initialization
Assembly: Metalama.Framework.dll
Syntax
public readonly struct InitializationContext
Remarks

This struct is 16 bytes on x64 (no wasted padding): a CallerIntent byte, a uint slot bitmask, and an optional InitializationMetadata reference.

default(InitializationContext) is valid and equivalent to Default: Intent is None, no slots, no metadata.

Properties

Name Description
Default

The default context — None, no slots, no metadata.

Intent

The caller's intent regarding Initialize(InitializationContext) invocation.

Metadata

Optional metadata describing the initialization context. Typically a singleton. Returns null for default construction (equivalent to Default).

Modify

A context for with expressions or clone operations. The Initialize(InitializationContext) method (typically invoked via WithInitialize<T>(T, InitializationMetadata?)) should revalidate invariants and reinitialize derived state.

WillCallOnInitialized

Whether Initialize(InitializationContext) will be called by the caller. true when Intent is WillInitialize.

WillInitialize

A context signaling that the caller will call Initialize(InitializationContext) after construction (e.g., after an object initializer).

Methods

Name Description
Create(InitializationMetadata)

Creates a context with the given metadata. Used when calling Initialize(InitializationContext) directly (not via a constructor), e.g., after deserialization or a with expression. The resulting context has WillInitialize, signaling to descendants that Initialize(InitializationContext) is being invoked.

Descend(InitializationSlot)

Returns a copy of the current context with the given slots added to the handled set, suitable for passing to base.Initialize(...) from a derived Initialize(InitializationContext) override. Each slot tells the base layer that the derived type will handle the corresponding concern itself.

IsHandled(InitializationSlot)

Returns true when the given InitializationSlot is set in this context, meaning a derived type has guaranteed it will handle the corresponding concern itself. Aspects whose templates share a slot use this to skip work that a more-derived layer has already taken responsibility for.