API reference — Event store
Nuvora.Nexus.Relay.EventStore
Core event store abstractions and implementations for Nuvora Nexus Relay
dotnet add package Nuvora.Nexus.Relay.EventStore
Nuvora.Nexus.Relay.EventStore
ConcurrencyConflictException
public sealed class ConcurrencyConflictException : Exception
Thrown when an append to the event store violates the expected version for an aggregate, i.e. another writer advanced the stream concurrently (optimistic concurrency conflict).
Constructors
ConcurrencyConflictException(Guid aggregateId, long expectedVersion, long? actualVersion = null, Exception? innerException = null)
Properties
Guid AggregateId { get; }
long ExpectedVersion { get; }
Version the caller expected the stream to be at.
long? ActualVersion { get; }
Version actually found in the store, when known (otherwise null).
Methods
static ConcurrencyConflictException ForUnknownConflict(Exception? innerException = null)
Conflict detected by the database’s unique (aggregate_id, version) index, but the error detail carrying the conflicting key was unavailable (e.g. restricted error verbosity), so the aggregate id and version are unknown. ConcurrencyConflictException.AggregateId is Guid.Empty and ConcurrencyConflictException.ExpectedVersion is -1 as placeholders only.
static ConcurrencyConflictException ForVersionConflict(Guid aggregateId, long conflictingVersion, Exception? innerException = null)
Conflict detected by the database’s unique (aggregate_id, version) index: an event at conflictingVersion already exists, so the attempted insert at that version lost the race. The writer’s implied expected version is conflictingVersion - 1; the store’s actual head is unknown (at least conflictingVersion).
DefaultEventSerializer
public class DefaultEventSerializer : IEventSerializer
Default IEventSerializer using Newtonsoft.Json for the payload and an IEventTypeRegistry for stable type naming/resolution. On read, payloads are run through the ordered IEventUpcaster chain before deserialization so historical events survive schema evolution.
Constructors
DefaultEventSerializer(IEventTypeRegistry registry, IEnumerable<IEventUpcaster>? upcasters = null)
Methods
EventData SerializeAccessEvent(IAccessEvent accessEvent, long position, string? metadata = null)
Serialize an access event to EventData
EventData SerializeDomainEvent(IDomainEvent domainEvent, Guid aggregateId, string aggregateType, long version, long position, string? metadata = null)
Serialize a domain event to EventData
EventData SerializeIntegrationEvent(IIntegrationEvent integrationEvent, long position, string? metadata = null)
Serialize an integration event to EventData
IMessage DeserializeEvent(EventData eventData)
Deserialize EventData back to an IMessage
TEvent DeserializeEvent<TEvent>(EventData eventData)
Deserialize EventData to a specific event type
EventCursor
public readonly record struct EventCursor : IComparable<EventCursor>, IEquatable<EventCursor>
A gap-safe forward-reading position in the global event log. Combines the inserting transaction id (EventCursor.TxId) with the database identity (EventCursor.Position).
Why both. global_position is a database identity allocated at INSERT but made visible at COMMIT, and commit order is not allocation order — a transaction that acquires its transaction id early (e.g. by writing the outbox/snapshot row first) can later insert an event with a lower position than an already-committed event from an earlier transaction. A reader that checkpoints on position alone would advance past that lower position while it is still invisible and skip it forever. Ordering and checkpointing on (tx_id, position) instead is gap-safe: catch-up readers cap each batch at the visibility horizon (the oldest still-running transaction), so every transaction at or below the cursor’s EventCursor.TxId is final, and a later-committing transaction always has a strictly greater EventCursor.TxId and is therefore read, never skipped.
Constructors
EventCursor(long TxId, long Position)
A gap-safe forward-reading position in the global event log. Combines the inserting transaction id (EventCursor.TxId) with the database identity (EventCursor.Position). Why both. global_position is a database identity allocated at INSERT but made visible at COMMIT, and commit order is not allocation order — a transaction that acquires its transaction id early (e.g. by writing the outbox/snapshot row first) can later insert an event with a lower position than an already-committed event from an earlier transaction. A reader that checkpoints on position alone would advance past that lower position while it is still invisible and skip it forever. Ordering and checkpointing on (tx_id, position) instead is gap-safe: catch-up readers cap each batch at the visibility horizon (the oldest still-running transaction), so every transaction at or below the cursor’s EventCursor.TxId is final, and a later-committing transaction always has a strictly greater EventCursor.TxId and is therefore read, never skipped.
Properties
long Position { get; init; }
Global position of the last consumed event (0 = before the start).
long TxId { get; init; }
Inserting transaction id of the last consumed event (0 = before the start).
static EventCursor Start { get; }
The cursor before the first event (transaction 0, position 0).
Methods
int CompareTo(EventCursor other)
Total order over the log used for forward reads: by transaction id first, then by position within a transaction. Two distinct events never share both, so this is a strict total order.
Operators
static bool operator <(EventCursor left, EventCursor right)
static bool operator <=(EventCursor left, EventCursor right)
static bool operator >(EventCursor left, EventCursor right)
static bool operator >=(EventCursor left, EventCursor right)
EventData
public class EventData
Universal event wrapper for event store persistence
Constructors
EventData()
EventData(Guid eventId, string streamName, string eventType, Guid aggregateId, string aggregateType, long version, long position, DateTimeOffset timestamp, string data, string? metadata = null)
Properties
DateTimeOffset Timestamp { get; init; }
Guid AggregateId { get; init; }
Guid EventId { get; init; }
Guid? TenantId { get; init; }
Owning tenant of this event (the persisted tenant_id column), or null for a global / single-tenant event. Populated by the event store on read so downstream consumers (projection host, subscriptions) can filter per tenant; on append the store stamps the row from the ambient tenant accessor instead, so this property is not consulted on the write path.
long Position { get; init; }
long TxId { get; init; }
Inserting transaction id of this event (the tx_id column). Populated by the event store on read; together with EventData.Position it forms the gap-safe EventCursor that catch-up readers checkpoint on. Zero when the event was constructed off the store (e.g. an inbox or replay envelope), which never feeds a catch-up cursor.
long Version { get; init; }
string AggregateType { get; init; }
string Data { get; init; }
string EventType { get; init; }
string StreamName { get; init; }
string? Metadata { get; init; }
EventMetadata
public static class EventMetadata
Builds the JSON metadata stored with each persisted event: the framework’s CommandName and Timestamp, plus any entries contributed by registered IEventMetadataEnrichers. The built-in keys are written last, so they are always present and cannot be overwritten. With no enrichers the output is exactly {"CommandName":…,"Timestamp":…} — unchanged from before enrichers existed.
Methods
static string Build(string commandName, IEnumerable<IEventMetadataEnricher>? enrichers = null)
Serializes the per-event metadata for commandName, applying any enrichers first.
EventStoreVisibility
public readonly record struct EventStoreVisibility : IEquatable<EventStoreVisibility>
Snapshot of the event store’s read-visibility state under the lock-free ordering model.
Constructors
EventStoreVisibility(long ReadableHead, long CommittedHead)
Snapshot of the event store’s read-visibility state under the lock-free ordering model.
Properties
long CommittedHead { get; init; }
Highest global position among all committed events, including those still held back by an older in-flight transaction.
long Lag { get; }
Committed events not yet readable by catch-up consumers (CommittedHead − ReadableHead, in positions). Persistently non-zero means a long-running write transaction is stalling the visibility horizon — and with it every projection and subscription.
long ReadableHead { get; init; }
Highest global position catch-up readers may safely consume (capped at the visibility horizon — the oldest still-running transaction).
EventTypeAttribute
public sealed class EventTypeAttribute : Attribute
Pins a stable persisted name to an event type, decoupling the stored event_type from the CLR Type.FullName. Once events are in the store, the name must never change even if the class is renamed or moved; bump the suffix (e.g. "order.placed.v2") for a new shape and supply an IEventUpcaster to migrate old payloads on read.
Constructors
EventTypeAttribute(string name)
Properties
string Name { get; }
EventTypeRegistry
public sealed class EventTypeRegistry : IEventTypeRegistry
Thread-safe IEventTypeRegistry. Resolution is registry-only: a stored type name resolves exclusively through the explicit map populated by EventTypeRegistry.Register / EventTypeRegistry.RegisterAssemblies. There is deliberately no Type.GetType fallback — resolving CLR (or assembly-qualified) type names straight from stored strings would let database content pick arbitrary types, and made misses silently dependent on what happened to be loaded. Register your event assemblies via AddRelay.
Methods
bool TryResolveClrType(string typeName, out Type clrType)
Resolves a persisted name back to its CLR type.
string GetTypeName(Type clrType)
Stable persisted name for a CLR type (attribute override, else Type.FullName).
void Register(Type clrType, string? typeName = null)
Registers a mapping from clrType to its stable stored name. Re-registering the same type under the same name is idempotent; mapping an already-registered name to a different CLR type throws, because a silent last-write-wins would make historical events deserialize into the wrong type.
void RegisterAssemblies(IEnumerable<Assembly> assemblies, IEnumerable<Type> markerInterfaces)
Scans the supplied assemblies and registers every concrete domain/integration/access event.
IEventMetadataEnricher
public interface IEventMetadataEnricher
Contributes extra entries to the metadata persisted alongside each event (e.g. user id, tenant, trace id, custom headers). Every registered enricher runs for each command’s event append. The framework always stamps CommandName and Timestamp afterwards, so those keys are authoritative and cannot be overwritten by an enricher. Implementations must be cheap and side-effect-free (they run inside the command’s commit path).
Methods
void Enrich(IDictionary<string, object?> metadata, string commandName)
Adds entries to the per-event metadata bag for the given command.
IEventSerializer
public interface IEventSerializer
Interface for serializing and deserializing events
Methods
EventData SerializeAccessEvent(IAccessEvent accessEvent, long position, string? metadata = null)
Serialize an access event to EventData
EventData SerializeDomainEvent(IDomainEvent domainEvent, Guid aggregateId, string aggregateType, long version, long position, string? metadata = null)
Serialize a domain event to EventData
EventData SerializeIntegrationEvent(IIntegrationEvent integrationEvent, long position, string? metadata = null)
Serialize an integration event to EventData
IMessage DeserializeEvent(EventData eventData)
Deserialize EventData back to an IMessage
TEvent DeserializeEvent<TEvent>(EventData eventData)
Deserialize EventData to a specific event type
IEventSourcedReader<TAggregate, TId>
public interface IEventSourcedReader<TAggregate, TId> where TAggregate : AggregateRoot<TId> where TId : notnull
Read-only, point-in-time rehydration of event-sourced aggregates by folding their event stream on demand — without snapshots and without tracking the aggregate on the unit of work. Complements IEventSourcedRepository (which loads the current state for writing) with “live aggregation” and time-travel reads for the query side.
Methods
Task<TAggregate?> LoadAsync(TId id, CancellationToken cancellationToken = default(CancellationToken))
Rehydrates the aggregate’s current state by replaying its whole stream (live aggregation). Returns null if the aggregate has no events.
Task<TAggregate?> LoadAtTimeAsync(TId id, DateTimeOffset asOf, CancellationToken cancellationToken = default(CancellationToken))
Rehydrates the aggregate as it stood at asOf (events whose timestamp is at or before it). Returns null if it had no events by then.
Task<TAggregate?> LoadAtVersionAsync(TId id, long version, CancellationToken cancellationToken = default(CancellationToken))
Rehydrates the aggregate as of (and including) version. Returns null if it had no events at or below that version.
IEventSourcedRepository<TAggregate, TId>
public interface IEventSourcedRepository<TAggregate, TId> where TAggregate : AggregateRoot<TId> where TId : notnull
Loads and tracks event-sourced aggregates. Loading rehydrates from the latest snapshot (when the aggregate is ISnapshotable) plus the events after it, falling back to a full replay. Saving merely tracks the aggregate on the unit of work; the transaction behavior serializes, appends and dispatches its events atomically at commit — one persistence path.
Methods
Task<TAggregate?> GetByIdAsync(TId id, CancellationToken cancellationToken = default(CancellationToken))
Rehydrates the aggregate, or returns null if it has no events.
void Add(TAggregate aggregate)
Tracks a new aggregate so its events are appended at commit.
void Update(TAggregate aggregate)
Tracks a loaded aggregate so its new events are appended at commit.
IEventStore
public interface IEventStore
Main interface for event store operations
Methods
Task AppendAsync(EventData eventData, long? expectedVersion = null, CancellationToken cancellationToken = default(CancellationToken))
Append a single event to the event store
Task AppendManyAsync(IEnumerable<EventData> events, long? expectedVersion = null, CancellationToken cancellationToken = default(CancellationToken))
Append multiple events to the event store atomically
Task<EventCursor> GetCursorAtAsync(long position, CancellationToken cancellationToken = default(CancellationToken))
Resolves a legacy numeric position into a gap-safe resume EventCursor so a catch-up reader can resume near position without replaying the whole log. Needed because the transaction-ordered cursor cannot be reconstructed from a position alone — seeding (0, position) would sort before every real transaction and re-read everything. Implementations must resolve conservatively: the returned cursor may cause events at or below the position to be re-delivered (handlers are idempotent by contract) but must never cause an event above it to be skipped. Returns EventCursor.Start for a non-positive position. The default returns (0, position) (correct for single-transaction-id stores); the PostgreSQL store overrides it with a horizon-capped lookup of a provably-safe transaction id.
Task<EventCursor> GetReadableHeadCursorAsync(CancellationToken cancellationToken = default(CancellationToken))
The readable head as a gap-safe EventCursor: the maximum (tx_id, position) among events below the visibility horizon. A catch-up reader that has consumed up to this cursor is fully caught up — used by the projection host’s cheap idle-skip pre-pass so it compares like for like with the checkpoint cursor (comparing the cursor against a position-only head can read as perpetually-behind when the highest-position event is not in the highest-id transaction). The default implementation returns (0, GetCurrentPositionAsync()), correct for stores whose events share a single transaction id (e.g. in-memory); the PostgreSQL store overrides it.
Task<IReadOnlyList<EventData>> GetAllEventsAsync(long fromPosition = 0, int? maxCount = null, CancellationToken cancellationToken = default(CancellationToken))
Get all events from the global event log
Task<IReadOnlyList<EventData>> GetAllEventsAsync(string aggregateType, long fromPosition = 0, int? maxCount = null, CancellationToken cancellationToken = default(CancellationToken))
Get events from the global log filtered by aggregate type, in global-position order. Default implementation filters client-side; stores should override with an indexed server-side filter (the EF Core store uses the (aggregate_type, global_position) index).
Task<IReadOnlyList<EventData>> GetEventsAsync(Guid aggregateId, long fromVersion = 0, CancellationToken cancellationToken = default(CancellationToken))
Get all events for a specific aggregate
Task<IReadOnlyList<EventData>> GetEventsByTypeAsync(string eventType, long fromPosition = 0, int? maxCount = null, CancellationToken cancellationToken = default(CancellationToken))
Get events by event type
Task<IReadOnlyList<EventData>> GetStreamEventsAsync(string streamName, long fromPosition = 0, CancellationToken cancellationToken = default(CancellationToken))
Get all events for a specific stream
Task<IReadOnlyList<EventData>> GetStreamEventsAsync(string streamName, long fromPosition, int? maxCount, CancellationToken cancellationToken = default(CancellationToken))
Get events for a specific stream, bounded to at most maxCount events. Default implementation reads the full stream and truncates client-side; stores should override with a server-side limit (the EF Core store does).
Task<IReadOnlyList<EventData>> QueryEventsAsync(Func<EventData, bool> predicate, int maxResults = 100, CancellationToken cancellationToken = default(CancellationToken))
Ad-hoc query over the global log: returns up to maxResults events matching predicate, in global-position order. The default implementation pages the log and filters in-process — a full scan, intended for diagnostics and one-off read-model builds, not hot paths; stores may override with a server-side query (e.g. a PostgreSQL jsonb filter).
Task<IReadOnlyList<EventData>> ReadForwardAsync(EventCursor from, int? maxCount = null, string? aggregateType = null, string? eventType = null, CancellationToken cancellationToken = default(CancellationToken))
Gap-safe forward read of the global log for catch-up readers (projections, subscriptions), ordered by (tx_id, global_position) and capped at the visibility horizon. Resuming from the returned events’ EventCursor (their EventData.TxId + EventData.Position) is forward-only safe: a transaction that commits after the reader passed has a strictly greater transaction id and is read on a later pass, never skipped — unlike a position-only checkpoint, which a late-committing low position can slip under. The default implementation delegates to the position-ordered IEventStore.GetAllEventsAsync with client-side filtering; it is adequate for in-memory stores but is not gap-safe. The PostgreSQL store overrides it with the transaction-ordered query that is.
Task<bool> AggregateExistsAsync(Guid aggregateId, CancellationToken cancellationToken = default(CancellationToken))
Check if an aggregate exists
Task<long> GetAggregateVersionAsync(Guid aggregateId, CancellationToken cancellationToken = default(CancellationToken))
Get the current version of an aggregate
Task<long> GetCurrentPositionAsync(CancellationToken cancellationToken = default(CancellationToken))
Get the current global position
IEventStoreSubscription
public interface IEventStoreSubscription
Interface for subscribing to event store streams
Methods
Task<IEventSubscription> SubscribeToAllAsync(Func<EventData, CancellationToken, Task> handler, long fromPosition = 0, Func<EventData, bool>? filter = null, CancellationToken cancellationToken = default(CancellationToken))
Subscribe to all events from the global event log
Task<IEventSubscription> SubscribeToEventTypeAsync(string eventType, Func<EventData, CancellationToken, Task> handler, long fromPosition = 0, CancellationToken cancellationToken = default(CancellationToken))
Subscribe to events by type
Task<IEventSubscription> SubscribeToStreamAsync(string streamName, Func<EventData, CancellationToken, Task> handler, long fromPosition = 0, CancellationToken cancellationToken = default(CancellationToken))
Subscribe to events from a specific stream
IEventStoreVisibility
public interface IEventStoreVisibility
Optional diagnostic surface of visibility-horizon event stores: how far read visibility trails the committed log. Implemented by the EF Core (PostgreSQL) store; consumed by the projection lag monitor to publish the relay.events.visibility_lag gauge and warn on stalled horizons.
Methods
Task<EventStoreVisibility> GetVisibilityAsync(CancellationToken cancellationToken = default(CancellationToken))
Reads the current readable/committed head positions.
IEventSubscription
public interface IEventSubscription
Represents an active event subscription
Properties
bool IsActive { get; }
Whether the subscription is active
long CurrentPosition { get; }
Current position of the subscription
string SubscriptionId { get; }
Unique subscription ID
string? StreamName { get; }
Stream name being subscribed to (null for global subscriptions)
Methods
Task UnsubscribeAsync(CancellationToken cancellationToken = default(CancellationToken))
Unsubscribe from the stream
IEventTypeRegistry
public interface IEventTypeRegistry
Bidirectional map between CLR event types and their stable persisted names. Populated at startup by scanning the application assemblies for events (honouring EventTypeAttribute), it is the single source of truth for what goes into the event_type column and how that string is resolved back to a type on read — replacing brittle all-assemblies type scans.
Methods
bool TryResolveClrType(string typeName, out Type clrType)
Resolves a persisted name back to its CLR type.
string GetTypeName(Type clrType)
Stable persisted name for a CLR type (attribute override, else Type.FullName).
void Register(Type clrType, string? typeName = null)
Registers a type under the supplied name (or its conventional name when null).
IEventUpcaster
public interface IEventUpcaster
Migrates a stored event payload from an older shape to a newer one on read, so historical events remain loadable after the event schema evolves. Upcasters form an ordered chain: the serializer applies each applicable upcaster in turn (an upcaster may also rename the event type, e.g. "order.placed.v1" → "order.placed.v2") until the payload reaches its current shape.
Methods
(string TypeName, JObject Json) Upcast(string typeName, JObject json)
Returns the (possibly new) type name and (possibly rewritten) JSON for the next stage. Must be pure with respect to json ownership — callers pass a mutable clone.
bool CanUpcast(string typeName)
Whether this upcaster applies to the given (current) persisted type name.
IInlineEventProjection
public interface IInlineEventProjection
A projection applied synchronously (inline) inside the command’s transaction — immediately after the aggregate’s events are appended and before commit — so the read model it maintains is updated atomically with the events (read-your-writes, with no catch-up lag). Contrast with the asynchronous projection host, which catches up after commit. Stage writes on the shared scoped DbContext and do not call SaveChanges; the unit of work commits the read-model changes together with the events. Register one or more as IInlineEventProjection in DI; when none are registered the command path is unchanged. Note the event’s global EventData.Position is not yet assigned (0) at inline time — it is allocated at commit.
Methods
Task ApplyAsync(EventData @event, CancellationToken cancellationToken = default(CancellationToken))
Applies an appended event to the inline read model, staged on the shared DbContext.
bool Handles(string eventType)
Whether this inline projection handles the given (fully-qualified) event type.
IRelayDbContextAccessor
public interface IRelayDbContextAccessor
Exposes the host application’s database context to Relay infrastructure (event store, outbox, snapshots) without coupling the abstraction packages to Entity Framework Core. The EF Core implementation registers an accessor over the same scoped DbContext the command’s unit of work uses, so event-append, state changes and outbox writes all enlist in the single transaction that the unit of work commits — making them atomic (no dual-write). The value is intentionally typed as Object; the EF Core package casts it to Microsoft.EntityFrameworkCore.DbContext.
Properties
object DbContext { get; }
The ambient database context for the current scope.
ISubscriptionStore
public interface ISubscriptionStore
A durable, named subscription position over the global event log — generalizes projection checkpoints to arbitrary catch-up consumers. A consumer reads forward from ISubscriptionStore.GetPositionAsync (using the gap-safe EventCursor) and acknowledges progress with ISubscriptionStore.AdvanceAsync. The stored position is monotonic (it never moves backwards), and delivery is at-least-once, so consumers must be idempotent. Implementations are thread-safe.
Methods
Task AdvanceAsync(string subscriptionName, EventCursor cursor, CancellationToken cancellationToken = default(CancellationToken))
Acknowledges the named subscription up to cursor. Monotonic: an attempt to move the position backwards (or to the same place) is ignored.
Task<EventCursor> GetPositionAsync(string subscriptionName, CancellationToken cancellationToken = default(CancellationToken))
The last acknowledged cursor for the named subscription, or EventCursor.Start if none.
StreamName
public static class StreamName
Utility class for generating consistent stream names
Methods
static Guid? ParseAggregateId(string streamName)
Parse aggregate ID from stream name
static string ForAccessEvent(Type eventType)
Generate stream name for access events
static string ForAggregate(Type aggregateType, Guid aggregateId)
Generate stream name for an aggregate
static string ForAggregate(string aggregateTypeName, Guid aggregateId)
Generate stream name for an aggregate from its stored type name (e.g. the aggregate_type metadata, typically a CLR full name). Only the simple type name (the segment after the last . or nested-type +) is used, matching StreamName.ForAggregate.
static string ForAggregate<TAggregate>(Guid aggregateId)
Generate stream name for an aggregate
static string ForIntegrationEvent(Type eventType)
Generate stream name for integration events
static string? ParseAggregateType(string streamName)
Parse aggregate type name from stream name
Nuvora.Nexus.Relay.EventStore.Snapshots
ISnapshotStore
public interface ISnapshotStore
Persists and retrieves aggregate snapshots. Snapshots are an optimization only: a load path must always be able to fall back to a full event replay if a snapshot is missing or undeserializable.
Methods
Task SaveAsync(SnapshotData snapshot, CancellationToken cancellationToken = default(CancellationToken))
Saves a snapshot.
Task<SnapshotData?> GetLatestAsync(Guid aggregateId, CancellationToken cancellationToken = default(CancellationToken))
Gets the most recent snapshot for an aggregate, or null if none exists.
ISnapshotable
public interface ISnapshotable
Optional capability implemented by aggregates that support snapshotting. Aggregates that do not implement this are simply never snapshotted (and always load via full replay).
Methods
object GetSnapshotState()
Returns a serializable object representing the aggregate’s current state.
void RestoreFromSnapshot(object state, long version)
Restores aggregate state from a snapshot payload at the given version.
SnapshotData
public sealed record SnapshotData : IEquatable<SnapshotData>
A point-in-time serialized snapshot of an aggregate’s state at a specific version, used to avoid replaying an entire event stream on load.
Constructors
SnapshotData(Guid AggregateId, string AggregateType, long Version, string Payload, DateTimeOffset CreatedAt)
A point-in-time serialized snapshot of an aggregate’s state at a specific version, used to avoid replaying an entire event stream on load.
Properties
DateTimeOffset CreatedAt { get; init; }
When the snapshot was taken.
Guid AggregateId { get; init; }
Aggregate the snapshot belongs to.
long Version { get; init; }
The aggregate version captured by this snapshot.
string AggregateType { get; init; }
Fully-qualified aggregate type name (for schema/versioning).
string Payload { get; init; }
Serialized aggregate state (JSON).
SnapshotOptions
public sealed class SnapshotOptions
Controls automatic snapshotting of ISnapshotable aggregates by the transaction behavior. Snapshots are a load optimization only — correctness never depends on them.
Properties
int KeepSnapshots { get; set; }
How many of the most recent snapshots to keep per aggregate. When a new snapshot is staged, older rows beyond this count are deleted in the same transaction. Minimum effective value is 1 (always keep the newest). Defaults to 2 so the previous snapshot survives as a fallback while the newest one is fresh.
int SnapshotEvery { get; set; }
Take a snapshot whenever a command advances an aggregate across a multiple of this many events (e.g. 50 snapshots around versions 49, 99, …). 0 (default) disables snapshotting.