Interface ISnapshotStrategy
- Namespace
- Stratara.Abstractions.EventSourcing
- Assembly
- Stratara.Abstractions.dll
Decides whether the event-sourcing runtime should write a new snapshot for a stream that has just had events appended. This is the configurable replacement for the framework's formerly hard-coded "snapshot every 50 events, always on" policy.
public interface ISnapshotStrategy
- Extension Methods
Remarks
The default implementation registered by AddEventSourcing() snapshots a stream once
it has advanced by a fixed number of versions since its last snapshot (50 by default).
To take over the policy — for example to vary the threshold per aggregate type, or to turn
snapshots off entirely — register your own singleton implementation of this interface in DI.
The framework resolves the last-registered ISnapshotStrategy, so a custom
registration wins regardless of whether it runs before or after AddEventSourcing().
Methods
ShouldSnapshot(Type, long, long)
Determines whether a snapshot should be written for the stream described by the arguments.
bool ShouldSnapshot(Type aggregateType, long currentVersion, long lastSnapshotVersion)
Parameters
aggregateTypeTypeThe runtime aggregate type of the stream being evaluated.
currentVersionlongThe stream's highest version after the events just appended.
lastSnapshotVersionlongThe version of the most recent existing snapshot for the stream, or
0when the stream has no snapshot yet.
Returns
- bool
trueto write a fresh snapshot atcurrentVersion; otherwisefalse.