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 using the session's
tenant + user as AAD, serializes sessionContext to JSON, and wraps them in a
freshly-id'd CommandEnvelope. 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.