Table of Contents

Class SizeBasedSnapshotStrategy

Namespace
Excalibur.EventSourcing.Snapshots
Assembly
Excalibur.EventSourcing.dll

Snapshot strategy based on aggregate size in memory.

public sealed class SizeBasedSnapshotStrategy : ISnapshotStrategy
Inheritance
SizeBasedSnapshotStrategy
Implements
Inherited Members

Remarks

Creates a snapshot when the estimated memory size of an aggregate exceeds a threshold. Useful for aggregates with large event payloads or many uncommitted events.

Constructors

SizeBasedSnapshotStrategy(long)

Initializes a new instance of the SizeBasedSnapshotStrategy class.

public SizeBasedSnapshotStrategy(long maxSizeInBytes = 1048576)

Parameters

maxSizeInBytes long

Maximum aggregate size in bytes before creating a snapshot. Default is 1MB.

Exceptions

ArgumentOutOfRangeException

Thrown when max size is zero or negative.

Methods

ShouldCreateSnapshot(IAggregateRoot)

Determines whether a snapshot should be created for the aggregate.

[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
[RequiresDynamicCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
public bool ShouldCreateSnapshot(IAggregateRoot aggregate)

Parameters

aggregate IAggregateRoot

The aggregate to check.

Returns

bool

True if a snapshot should be created, otherwise false.