Table of Contents

Interface IMessageContextFactory

Namespace
Excalibur.Dispatch.Delivery
Assembly
Excalibur.Dispatch.dll

Factory for creating message context instances.

public interface IMessageContextFactory
Extension Methods

Methods

CreateChildContext(IMessageContext)

Creates a child context from a parent context, propagating cross-cutting identifiers.

IMessageContext CreateChildContext(IMessageContext parent)

Parameters

parent IMessageContext

The parent context to derive from.

Returns

IMessageContext

A new message context with propagated identifiers from the parent.

Remarks

The child context propagates:

  • CorrelationId - Copied from parent
  • TenantId - Copied from parent
  • UserId - Copied from parent
  • SessionId - Copied from parent
  • WorkflowId - Copied from parent
  • TraceParent - Copied from parent
  • Source - Copied from parent
  • CausationId - Set to parent's MessageId

A new MessageId is generated for the child context.

CreateContext()

Creates a new message context.

IMessageContext CreateContext()

Returns

IMessageContext

A new message context instance.

CreateContext(IDictionary<string, object>)

Creates a new message context with the specified properties.

IMessageContext CreateContext(IDictionary<string, object> properties)

Parameters

properties IDictionary<string, object>

Initial properties for the context.

Returns

IMessageContext

A new message context instance.

Return(IMessageContext)

Returns a message context to the pool after use.

void Return(IMessageContext context)

Parameters

context IMessageContext

The context to return.

Remarks

This method should be called when a message context is no longer needed. For pooled factory implementations, the context is returned to the pool for reuse. For non-pooled implementations, this is a no-op.

Usage pattern:

var context = factory.CreateContext();
try
{
    await ProcessAsync(context);
}
finally
{
    factory.Return(context);
}