Table of Contents

Class MessageContextExtensions

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

Extension methods for IMessageContext.

public static class MessageContextExtensions
Inheritance
MessageContextExtensions
Inherited Members

Methods

AuthorizationResult(IMessageContext)

Gets the authorization result.

public static object? AuthorizationResult(this IMessageContext context)

Parameters

context IMessageContext

Returns

object

AuthorizationResult(IMessageContext, object?)

Sets the authorization result.

public static void AuthorizationResult(this IMessageContext context, object? value)

Parameters

context IMessageContext
value object

ContainsItem(IMessageContext, string)

Determines whether the Items dictionary contains the specified key.

public static bool ContainsItem(this IMessageContext context, string key)

Parameters

context IMessageContext

The message context.

key string

The key to check for existence.

Returns

bool

True if the key exists; otherwise, false.

ContractVersion(IMessageContext)

Gets the contract version.

public static string? ContractVersion(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

ContractVersion(IMessageContext, string?)

Sets the contract version.

public static void ContractVersion(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

DesiredVersion(IMessageContext)

Gets the desired version.

public static string? DesiredVersion(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

DesiredVersion(IMessageContext, string?)

Sets the desired version.

public static void DesiredVersion(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

GetContentType(IMessageContext)

Gets the content type from Items.

public static string? GetContentType(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

GetDestination(IMessageContext)

Gets the routing destination for this message.

public static string? GetDestination(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Returns

string

The destination, or null if not set.

GetInboxTransactionScope(IMessageContext)

Gets the provider-native inbox transaction scope for the message currently being processed, or null when the message is not being processed under a scoped transactional inbox store.

public static IInboxTransactionScope? GetInboxTransactionScope(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Returns

IInboxTransactionScope

The opaque IInboxTransactionScope the inbox handler can enlist its own writes in (context.GetInboxTransactionScope()?.AsMongoSession() for MongoDB, ?.AsCosmosBatch() for Cosmos DB), or null when there is no scoped transaction — meaning the handler runs under the at-least-once idempotent claim path and should use its own connection/session (its writes are then NOT atomic with the inbox processed-mark; the handler must be idempotent).

Remarks

This is the consumer enlistment API for exactly-once document-store inbox processing. A non-null scope means the store handed the middleware a native transaction (a MongoDB session / a Cosmos DB TransactionalBatch); writes the handler enlists on it commit atomically with the processed-mark. A null result is the normal, expected signal that the current store or configuration does not support scoped transactional processing.

GetItem<T>(IMessageContext, string)

Gets an item from the Items dictionary, returning null if not found.

public static T? GetItem<T>(this IMessageContext context, string key)

Parameters

context IMessageContext

The message context.

key string

The key of the item to retrieve.

Returns

T

The item cast to type T, or null if not found or wrong type.

Type Parameters

T

The type to cast the item to.

GetItem<T>(IMessageContext, string, T)

Gets an item from the Items dictionary, returning a default value if not found.

public static T GetItem<T>(this IMessageContext context, string key, T defaultValue)

Parameters

context IMessageContext

The message context.

key string

The key of the item to retrieve.

defaultValue T

The value to return if the key is not found.

Returns

T

The item cast to type T, or the default value if not found.

Type Parameters

T

The type to cast the item to.

GetMessageType(IMessageContext)

Gets the message type from Items.

public static string? GetMessageType(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

Remarks

MessageContext keeps this value in a dedicated field and is read from there, mirroring how correlation and causation are already special-cased for that type: every dispatch reads and writes the message type, and routing it through the Items dictionary cost a hash lookup per read and per write on the hot path. Once Items is materialized, the dictionary is authoritative, including removal of an entry. Custom derived contexts use their interface dictionary; the sealed framework-owned pooled context explicitly uses inherited storage.

GetProperty<T>(IMessageContext, string)

Gets a property from the context Items dictionary.

public static T? GetProperty<T>(this IMessageContext context, string key)

Parameters

context IMessageContext
key string

Returns

T

Type Parameters

T

GetReceivedTimestampUtc(IMessageContext)

Gets the received timestamp from Items.

public static DateTimeOffset? GetReceivedTimestampUtc(this IMessageContext context)

Parameters

context IMessageContext

Returns

DateTimeOffset?

GetSentTimestampUtc(IMessageContext)

Gets the sent timestamp from Items.

public static DateTimeOffset? GetSentTimestampUtc(this IMessageContext context)

Parameters

context IMessageContext

Returns

DateTimeOffset?

HasTransportBinding(IMessageContext)

Gets a value indicating whether this message was received via a transport adapter.

public static bool HasTransportBinding(this IMessageContext context)

Parameters

context IMessageContext

Returns

bool

IsMessageTypeRoutingDefault(IMessageContext)

Indicates whether GetMessageType(IMessageContext) holds a framework-defaulted routing name rather than a preserved foreign identity.

public static bool IsMessageTypeRoutingDefault(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Returns

bool

true if MarkMessageTypeAsRoutingDefault(IMessageContext) was called for this context; otherwise false, meaning the value (if any) was set by something other than the dispatcher's own default and must be preserved verbatim.

Exceptions

ArgumentNullException

context is null.

MarkMessageTypeAsRoutingDefault(IMessageContext)

Records that GetMessageType(IMessageContext) holds a routing name the framework defaulted in from the CLR type, rather than a foreign identity received from elsewhere and preserved verbatim.

public static void MarkMessageTypeAsRoutingDefault(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Remarks

A context's message type has two possible provenances that share one field: a CloudEvent identity received from another organisation, which a converter must re-emit verbatim, or a routing name this dispatcher defaulted in because nothing set one. The two require opposite handling and are otherwise indistinguishable from the stored string alone.

Call this only where the value is being defaulted, mirroring MarkOrderingEnforced(IMessageContext): mark the case the framework itself produces, and leave every other case — an inbound receive bridge stamping a foreign identity — unmarked and untouched.

Exceptions

ArgumentNullException

context is null.

MessageVersion(IMessageContext)

Gets the message version.

public static string? MessageVersion(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

MessageVersion(IMessageContext, string?)

Sets the message version.

public static void MessageVersion(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

Metadata(IMessageContext)

Gets metadata dictionary.

public static IDictionary<string, object>? Metadata(this IMessageContext context)

Parameters

context IMessageContext

Returns

IDictionary<string, object>

Metadata(IMessageContext, IDictionary<string, object>?)

Sets metadata dictionary.

public static void Metadata(this IMessageContext context, IDictionary<string, object>? value)

Parameters

context IMessageContext
value IDictionary<string, object>

PartitionKey(IMessageContext)

Gets the partition key from Items (alias for routing feature partition key).

public static string? PartitionKey(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

PartitionKey(IMessageContext, string?)

Sets the partition key in Items.

public static void PartitionKey(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

RemoveItem(IMessageContext, string)

Removes an item from the Items dictionary.

public static void RemoveItem(this IMessageContext context, string key)

Parameters

context IMessageContext

The message context.

key string

The key of the item to remove.

RemoveProperty(IMessageContext, string)

Removes a property from the context Items dictionary.

public static void RemoveProperty(this IMessageContext context, string key)

Parameters

context IMessageContext
key string

ReplyTo(IMessageContext)

Gets the reply-to address.

public static string? ReplyTo(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

ReplyTo(IMessageContext, string?)

Sets the reply-to address.

public static void ReplyTo(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

SerializerVersion(IMessageContext)

Gets the serializer version.

public static string? SerializerVersion(this IMessageContext context)

Parameters

context IMessageContext

Returns

string

SerializerVersion(IMessageContext, string?)

Sets the serializer version.

public static void SerializerVersion(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

SetContentType(IMessageContext, string?)

Sets the content type in Items.

public static void SetContentType(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

SetDestination(IMessageContext, string?)

Sets the routing destination for this message. Uses the canonical Destination key so the value flows through ExtractMetadata to the persisted message's destination.

public static void SetDestination(this IMessageContext context, string? value)

Parameters

context IMessageContext

The message context.

value string

The destination to set.

SetItem<T>(IMessageContext, string, T)

Sets or updates an item in the Items dictionary.

public static void SetItem<T>(this IMessageContext context, string key, T value)

Parameters

context IMessageContext

The message context.

key string

The key to store the value under.

value T

The value to store.

Type Parameters

T

The type of the value to store.

SetMessageType(IMessageContext, string?)

Sets the message type in Items.

public static void SetMessageType(this IMessageContext context, string? value)

Parameters

context IMessageContext
value string

Remarks

See GetMessageType(IMessageContext) for why MessageContext stores this in a field. The value is still surfaced through Items for anything that enumerates or reads the dictionary. Passing null preserves an item with a null value. To remove the item instead, remove its entry from Items.

SetProperty<T>(IMessageContext, string, T)

Gets or sets a property in the context Items dictionary.

public static void SetProperty<T>(this IMessageContext context, string key, T value)

Parameters

context IMessageContext
key string
value T

Type Parameters

T

SetReceivedTimestampUtc(IMessageContext, DateTimeOffset?)

Sets the received timestamp in Items.

public static void SetReceivedTimestampUtc(this IMessageContext context, DateTimeOffset? value)

Parameters

context IMessageContext
value DateTimeOffset?

SetSentTimestampUtc(IMessageContext, DateTimeOffset?)

Sets the sent timestamp in Items.

public static void SetSentTimestampUtc(this IMessageContext context, DateTimeOffset? value)

Parameters

context IMessageContext
value DateTimeOffset?

TransportBinding(IMessageContext)

Gets the transport binding that received this message.

public static ITransportBinding? TransportBinding(this IMessageContext context)

Parameters

context IMessageContext

Returns

ITransportBinding

TryGetProperty<T>(IMessageContext, string, out T?)

Tries to get a property from the context Items dictionary.

public static bool TryGetProperty<T>(this IMessageContext context, string key, out T? value)

Parameters

context IMessageContext
key string
value T

Returns

bool

Type Parameters

T

TryGetValue<T>(IMessageContext, string, out T?)

Tries to get a value from the context Items dictionary.

public static bool TryGetValue<T>(this IMessageContext context, string key, out T? value)

Parameters

context IMessageContext
key string
value T

Returns

bool

Type Parameters

T

ValidationResult(IMessageContext)

Gets the validation result.

public static object? ValidationResult(this IMessageContext context)

Parameters

context IMessageContext

Returns

object

ValidationResult(IMessageContext, object?)

Sets the validation result.

public static void ValidationResult(this IMessageContext context, object? value)

Parameters

context IMessageContext
value object

VersionMetadata(IMessageContext)

Gets the version metadata.

public static object? VersionMetadata(this IMessageContext context)

Parameters

context IMessageContext

Returns

object

VersionMetadata(IMessageContext, object?)

Sets the version metadata.

public static void VersionMetadata(this IMessageContext context, object? value)

Parameters

context IMessageContext
value object