Class VersionThresholdSnapshotStrategy
- Namespace
- Stratara.Infrastructure.EventSourcing
- Assembly
- Stratara.Infrastructure.dll
Default ISnapshotStrategy: writes a snapshot once a stream has advanced by at least a fixed threshold of versions since its most recent snapshot. Applies the same threshold (DefaultThreshold unless overridden) to every aggregate type, reproducing the framework's historical "snapshot every 50 events" behaviour.
public sealed class VersionThresholdSnapshotStrategy : ISnapshotStrategy
- Inheritance
-
VersionThresholdSnapshotStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
Registered by AddEventSourcing() via TryAddSingleton, so a consumer-supplied
ISnapshotStrategy overrides it. Construct with a custom threshold to keep the
uniform policy but change the cadence.
Constructors
VersionThresholdSnapshotStrategy(int)
Initialises the strategy with the version distance that triggers a new snapshot.
public VersionThresholdSnapshotStrategy(int threshold = 50)
Parameters
thresholdintNumber of versions a stream must advance past its last snapshot before a new one is written. Defaults to DefaultThreshold.
Exceptions
- ArgumentOutOfRangeException
Thrown when
thresholdis less than 1.
Fields
DefaultThreshold
The threshold used when none is supplied: snapshot every 50 versions.
public const int DefaultThreshold = 50
Field Value
Methods
ShouldSnapshot(Type, long, long)
Determines whether a snapshot should be written for the stream described by the arguments.
public 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.