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
serializerISecureJsonSerializerDecrypts and deserializes the payloads.
typeResolverITrustedTypeResolverResolves a recorded type name against the trusted types.
upcasterPipelineIEventUpcasterPipelineUpcasts 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
serializerISecureJsonSerializertypeResolverITrustedTypeResolverupcasterPipelineIEventUpcasterPipelineloggerILogger<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
entriesIEnumerable<EventStreamEntry>The persisted stream entries.
relevanceEventRelevanceWhich events the reader has a use for.
cancellationTokenCancellationTokenToken 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
entriesIEnumerable<EventStreamEntry>The persisted stream entries to map.
cancellationTokenCancellationTokenToken observed during async secure deserialization.
Returns
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
messagesIEnumerable<EventMessage>The event messages.
relevanceEventRelevanceWhich events the reader has a use for.
cancellationTokenCancellationTokenToken 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
messagesIEnumerable<EventMessage>The event messages to map.
cancellationTokenCancellationTokenToken observed during async secure deserialization.