Skip to main content
Table of Contents

Class EventMapperFactory

Namespace
Stratara.Shared.EventSourcing.Mapping
Assembly
Stratara.Shared.dll

Default IEventMapperFactory implementation. Materializes typed IEvent instances from persisted EventStreamEntry rows or wire-level EventMessage envelopes by resolving the runtime event type, decrypting / deserializing the JSON payload through ISecureJsonSerializer, and constructing Event<TEvent> via a per-type cached compiled lambda factory.

public sealed class EventMapperFactory : IEventMapperFactory
Inheritance
EventMapperFactory
Implements
Inherited Members
Extension Methods

Remarks

The factory cache is process-wide and unbounded; the framework assumes a finite set of event types per host. AAD on the encrypted payload uses the subject (data-owner) tenant id, which matches TenantId.

Constructors

EventMapperFactory(ISecureJsonSerializer, ITrustedTypeResolver, IEventUpcasterPipeline)

Initializes the mapper without a logger; a skip that would be logged is not.

public EventMapperFactory(ISecureJsonSerializer serializer, ITrustedTypeResolver typeResolver, IEventUpcasterPipeline upcasterPipeline)

Parameters

serializer ISecureJsonSerializer

Decrypts and deserializes the payloads.

typeResolver ITrustedTypeResolver

Resolves a recorded type name against the trusted types.

upcasterPipeline IEventUpcasterPipeline

Upcasts a payload recorded under an older schema.

EventMapperFactory(ISecureJsonSerializer, ITrustedTypeResolver, IEventUpcasterPipeline, ILogger<EventMapperFactory>?)

Default IEventMapperFactory implementation. Materializes typed IEvent instances from persisted EventStreamEntry rows or wire-level EventMessage envelopes by resolving the runtime event type, decrypting / deserializing the JSON payload through ISecureJsonSerializer, and constructing Event<TEvent> via a per-type cached compiled lambda factory.

public EventMapperFactory(ISecureJsonSerializer serializer, ITrustedTypeResolver typeResolver, IEventUpcasterPipeline upcasterPipeline, ILogger<EventMapperFactory>? logger)

Parameters

serializer ISecureJsonSerializer
typeResolver ITrustedTypeResolver
upcasterPipeline IEventUpcasterPipeline
logger ILogger<EventMapperFactory>

Remarks

The factory cache is process-wide and unbounded; the framework assumes a finite set of event types per host. AAD on the encrypted payload uses the subject (data-owner) tenant id, which matches TenantId.

Methods

MapToEventsAsync(IEnumerable<EventStreamEntry>, EventRelevance, CancellationToken)

Map the persisted stream entries a reader has a use for, leaving every other entry unread.

public Task<IReadOnlyList<IEvent>> MapToEventsAsync(IEnumerable<EventStreamEntry> entries, EventRelevance relevance, CancellationToken cancellationToken = default)

Parameters

entries IEnumerable<EventStreamEntry>

The persisted stream entries.

relevance EventRelevance

Which events the reader has a use for.

cancellationToken CancellationToken

Token observed during async secure deserialization.

Returns

Task<IReadOnlyList<IEvent>>

The relevant events, in the entries' order.

Remarks

The default implementation maps every entry and keeps the relevant events, so an entry whose type is not registered still fails. The framework's mapper overrides it and resolves and decrypts only what relevance accepts. A decorator that forwards only the older overloads inherits the default and with it the older behaviour; a test double of this interface must set this overload up, or call its base.

MapToEventsAsync(IEnumerable<EventStreamEntry>, CancellationToken)

Map persisted stream entries to materialised events.

public Task<IReadOnlyList<IEvent>> MapToEventsAsync(IEnumerable<EventStreamEntry> entries, CancellationToken cancellationToken = default)

Parameters

entries IEnumerable<EventStreamEntry>

The persisted stream entries to map.

cancellationToken CancellationToken

Token observed during async secure deserialization.

Returns

Task<IReadOnlyList<IEvent>>

MapToEventsAsync(IEnumerable<EventMessage>, EventRelevance, CancellationToken)

Map the wire-level event messages a reader has a use for, leaving every other message unread.

public Task<IReadOnlyList<IEvent>> MapToEventsAsync(IEnumerable<EventMessage> messages, EventRelevance relevance, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<EventMessage>

The event messages.

relevance EventRelevance

Which events the reader has a use for.

cancellationToken CancellationToken

Token observed during async secure deserialization.

Returns

Task<IReadOnlyList<IEvent>>

The relevant events, in the messages' order.

Remarks

The default implementation maps every message and keeps the relevant events, so a message whose type is not registered still fails. The framework's mapper overrides it and resolves and decrypts only what relevance accepts. A decorator that forwards only the older overloads inherits the default and with it the older behaviour; a test double of this interface must set this overload up, or call its base.

MapToEventsAsync(IEnumerable<EventMessage>, CancellationToken)

Map wire-level event messages (e.g. from a bus) to materialised events.

public Task<IReadOnlyList<IEvent>> MapToEventsAsync(IEnumerable<EventMessage> messages, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<EventMessage>

The event messages to map.

cancellationToken CancellationToken

Token observed during async secure deserialization.

Returns

Task<IReadOnlyList<IEvent>>