Skip to main content
Table of Contents

Class CommandEnvelopeMapper

Namespace
Stratara.Shared.Mediator.Mapping
Assembly
Stratara.Shared.dll

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

command T

The command instance to serialize.

sessionContext SessionContext

Session context to embed for handler-side replay.

serializer ISecureJsonSerializer

The secure JSON serializer used to encrypt [EncryptData]-tagged fields.

cancellationToken CancellationToken

Token observed during the asynchronous serialization.

Returns

Task<CommandEnvelope>

A new CommandEnvelope ready to enqueue or publish.

Type Parameters

T

CLR type of the command being wrapped.