Skip to main content
Table of Contents

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

threshold int

Number of versions a stream must advance past its last snapshot before a new one is written. Defaults to DefaultThreshold.

Exceptions

ArgumentOutOfRangeException

Thrown when threshold is less than 1.

Fields

DefaultThreshold

The threshold used when none is supplied: snapshot every 50 versions.

public const int DefaultThreshold = 50

Field Value

int

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

aggregateType Type

The runtime aggregate type of the stream being evaluated.

currentVersion long

The stream's highest version after the events just appended.

lastSnapshotVersion long

The version of the most recent existing snapshot for the stream, or 0 when the stream has no snapshot yet.

Returns

bool

true to write a fresh snapshot at currentVersion; otherwise false.