Skip to main content
Table of Contents

Interface ISnapshotRepository

Namespace
Stratara.Abstractions.EventSourcing
Assembly
Stratara.Abstractions.dll

Repository over the snapshot table — periodic state captures that let the aggregation service skip replaying every event from the start of a stream.

public interface ISnapshotRepository
Extension Methods

Methods

AddAsync(Snapshot, CancellationToken)

Append a snapshot. Caller is responsible for the transactional save.

Task AddAsync(Snapshot snapshot, CancellationToken cancellationToken = default)

Parameters

snapshot Snapshot
cancellationToken CancellationToken

Returns

Task

GetAsync(Guid, string, long?, CancellationToken)

Returns the latest snapshot for streamId of the aggregate type identified by aggregateTypeName with a version no greater than toVersion, or null if none exists.

Task<Snapshot?> GetAsync(Guid streamId, string aggregateTypeName, long? toVersion = null, CancellationToken cancellationToken = default)

Parameters

streamId Guid

The stream to load a snapshot for.

aggregateTypeName string

The (assembly-)qualified name of the aggregate type to match.

toVersion long?

Upper version bound (inclusive), or null for the latest.

cancellationToken CancellationToken

Propagated to the query.

Returns

Task<Snapshot>

Remarks

The type match is version-independent: assembly version / culture / public-key-token segments are ignored so an assembly rev-bump does not invalidate existing snapshots. Scoping the read to the aggregate type is required — two aggregate types keyed on the same stream id must never rehydrate from each other's snapshot.

GetLatestVersionOrDefaultAsync(Guid, string, CancellationToken)

Returns the version of the most recent snapshot for the stream of the aggregate type identified by aggregateTypeName (version-independent match), or 0.

Task<long> GetLatestVersionOrDefaultAsync(Guid streamId, string aggregateTypeName, CancellationToken cancellationToken = default)

Parameters

streamId Guid

The stream to inspect.

aggregateTypeName string

The (assembly-)qualified name of the aggregate type to match.

cancellationToken CancellationToken

Propagated to the query.

Returns

Task<long>