Class SnapshotVersionManager
- Namespace
- Excalibur.EventSourcing.Snapshots
- Assembly
- Excalibur.EventSourcing.dll
Manages snapshot version upgrades by maintaining a registry of upgraders and finding optimal upgrade paths between versions using BFS.
public sealed class SnapshotVersionManager
- Inheritance
-
SnapshotVersionManager
- Inherited Members
Remarks
This is the snapshot counterpart to EventVersionManager, following the same BFS-based path finding pattern for version migrations.
Constructors
SnapshotVersionManager(IEnumerable<ISnapshotUpgrader>, ILogger<SnapshotVersionManager>)
Initializes a new instance of the SnapshotVersionManager class.
public SnapshotVersionManager(IEnumerable<ISnapshotUpgrader> upgraders, ILogger<SnapshotVersionManager> logger)
Parameters
upgradersIEnumerable<ISnapshotUpgrader>The upgraders to register.
loggerILogger<SnapshotVersionManager>The logger.
Methods
CanUpgrade(string, int, int)
Determines whether an upgrade path exists for the specified aggregate type and version.
public bool CanUpgrade(string aggregateType, int fromVersion, int toVersion)
Parameters
aggregateTypestringThe aggregate type.
fromVersionintThe source version.
toVersionintThe target version.
Returns
- bool
True if an upgrade path exists; otherwise, false.
GetRegisteredAggregateTypes()
Gets all registered aggregate types.
public IEnumerable<string> GetRegisteredAggregateTypes()
Returns
- IEnumerable<string>
A collection of registered aggregate types.
GetUpgradersForAggregateType(string)
Gets all upgraders for a specific aggregate type.
public IEnumerable<ISnapshotUpgrader> GetUpgradersForAggregateType(string aggregateType)
Parameters
aggregateTypestringThe aggregate type.
Returns
- IEnumerable<ISnapshotUpgrader>
A collection of upgraders for the aggregate type.
RegisterUpgrader(ISnapshotUpgrader)
Registers a snapshot upgrader.
public void RegisterUpgrader(ISnapshotUpgrader upgrader)
Parameters
upgraderISnapshotUpgraderThe upgrader to register.
Remarks
Type and version metadata is captured once at registration. Later changes to consumer getters do not remap an existing registration. The original upgrader performs the transformation.
Exceptions
- ArgumentNullException
Thrown when upgrader is null.
- InvalidOperationException
Thrown when an upgrader for the same aggregate type and version range already exists.
UpgradeSnapshot(string, byte[], int, int)
Upgrades snapshot data to the specified version.
public byte[] UpgradeSnapshot(string aggregateType, byte[] snapshotData, int fromVersion, int toVersion)
Parameters
aggregateTypestringThe aggregate type.
snapshotDatabyte[]The snapshot data bytes.
fromVersionintThe current version of the snapshot.
toVersionintThe target version.
Returns
- byte[]
The upgraded snapshot data bytes.
Remarks
The manager performs typed byte-array calls. Registered upgraders and their serializers must use operations compatible with the application's trimming and NativeAOT configuration.
Exceptions
- ArgumentException
Thrown when the aggregate type is null or empty.
- ArgumentNullException
Thrown when snapshotData is null.
- InvalidOperationException
Thrown when no upgrade path is found.