Class CommandEnvelopeMapper
Conversion helper that wraps an in-process ICommand instance and the originating
SessionContext into a wire-level CommandEnvelope suitable for the
outbox / message bus. Command payload is encrypted through ISecureJsonSerializer
so any [EncryptData]-decorated fields are end-to-end protected; the session-context envelope
remains plaintext because the receiving worker needs to read the routing-relevant tenant id before
it has the AAD available to decrypt anything else.
public static class CommandEnvelopeMapper
- Inheritance
-
CommandEnvelopeMapper
- Inherited Members
Methods
MapToAsync<T>(T, SessionContext, ISecureJsonSerializer, CancellationToken)
Encrypts command through serializer for the owner
ForTransit(object, SessionContext) resolves — the owner the command names through
INamesDataOwner, or the session's data-owner tenant and acting user — serializes
sessionContext to JSON, and wraps them in a freshly-id'd
CommandEnvelope. A named owner is recorded on the envelope so the receiving host
reads the command for it; an envelope for a command that names none carries no owner. The
envelope id is generated via CreateVersion7() so it doubles as a sortable
outbox row id.
public static Task<CommandEnvelope> MapToAsync<T>(this T command, SessionContext sessionContext, ISecureJsonSerializer serializer, CancellationToken cancellationToken = default) where T : ICommand
Parameters
commandTThe command instance to serialize.
sessionContextSessionContextSession context to embed for handler-side replay.
serializerISecureJsonSerializerThe secure JSON serializer used to encrypt
[EncryptData]-tagged fields.cancellationTokenCancellationTokenToken observed during the asynchronous serialization.
Returns
- Task<CommandEnvelope>
A new CommandEnvelope ready to enqueue or publish.
Type Parameters
TCLR type of the command being wrapped.
Exceptions
- ArgumentException
commandimplements INamesDataOwner and names an empty tenant or an empty user.