Table of Contents

Interface IMessageContext

Namespace
Excalibur.Dispatch
Assembly
Excalibur.Dispatch.Abstractions.dll

Provides context information for a message being processed through the dispatch pipeline.

public interface IMessageContext
Extension Methods

Remarks

The message context flows through the entire message processing pipeline. It provides:

  • Core identity fields (MessageId, CorrelationId, CausationId)
  • The message payload and handler result
  • A scoped service provider for dependency resolution
  • An Items dictionary for middleware data sharing
  • A Features dictionary for typed feature access (processing, validation, routing, etc.)

Cross-cutting concerns (identity, routing, processing state, validation, timeout, rate limiting, transactions) are accessed via typed feature interfaces in the Features dictionary. Use context.GetFeature<IMessageProcessingFeature>() or the convenience extension methods in MessageContextFeatureExtensions.

Follows the pattern of Microsoft.AspNetCore.Http.HttpContext: 7 core properties plus a typed feature collection for extensibility.

Properties

CausationId

Gets or sets the causation identifier linking this message to its cause.

string? CausationId { get; set; }

Property Value

string

The causation identifier or null.

CorrelationId

Gets or sets the correlation identifier for tracking related messages.

string? CorrelationId { get; set; }

Property Value

string

The correlation identifier or null.

Features

Gets the typed feature collection for accessing cross-cutting concerns.

IDictionary<Type, object> Features { get; }

Property Value

IDictionary<Type, object>

The features dictionary keyed by feature interface type.

Remarks

Features provide typed access to processing state, identity, routing, validation, timeout, rate limiting, and transaction contexts. Use extension methods from MessageContextFeatureExtensions for convenient access:

var processing = context.GetOrCreateProcessingFeature();
processing.ProcessingAttempts++;

Contract an implementation must keep — the same one Items states, and now load-bearing here too. Returns the one collection owned by this context. Never null. The same instance on every call, for the life of the context. Mutable, and a write is observable to every subsequent read. Returning a fresh collection per call satisfies the signature and breaks this framework silently: the propagated set (SetPropagatedItem(IMessageContext, string, string)) is stored here, so a context that forgets a feature write loses every marked value with nothing raised and nothing logged.

Items

Gets this context's request-local scratch collection.

IDictionary<string, object> Items { get; }

Property Value

IDictionary<string, object>

The request-local items collection owned by this message context.

Remarks

Request-local. Nothing in this framework serializes, persists, transmits or emits these entries. To carry a value beyond this process, mark it with SetPropagatedItem(IMessageContext, string, string) instead. The two collections are separate for the reason Activity keeps Tags and Baggage apart: whether a write crosses a trust boundary must be decided by the call, never by the spelling of a key.

Contract an implementation must keep. Returns the one collection owned by this context. Never null. The same instance on every call, for the life of the context. Mutable, and a write is observable to every subsequent read. Returning a fresh collection per call satisfies the signature and breaks this framework silently — several components write an entry through one call and read it back through another.

Message

Gets or sets the message being processed.

IDispatchMessage? Message { get; set; }

Property Value

IDispatchMessage

The message instance or null.

MessageId

Gets or sets the unique identifier for this message instance.

string? MessageId { get; set; }

Property Value

string

The unique identifier assigned to the message.

RequestServices

Gets or sets the scoped service provider for this message processing context.

IServiceProvider RequestServices { get; set; }

Property Value

IServiceProvider

The scoped service provider for this context.

Result

Gets or sets the result of processing the message.

object? Result { get; set; }

Property Value

object

The handler result or null.