Table of Contents

Class SnapshotUpgrader<TFrom, TTo>

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

Base implementation of ISnapshotUpgrader for typed snapshot transformations.

public abstract class SnapshotUpgrader<TFrom, TTo> : ISnapshotUpgrader where TFrom : class where TTo : class

Type Parameters

TFrom

The source snapshot data type (deserialized from old version).

TTo

The target snapshot data type (for new version).

Inheritance
SnapshotUpgrader<TFrom, TTo>
Implements
Inherited Members

Remarks

Provides a type-safe base class for implementing snapshot upgraders. Derived classes only need to implement the UpgradeSnapshot(TFrom) method with strongly-typed parameters.

This is the snapshot counterpart to EventUpgrader<TFrom, TTo>, following the same versioning pattern.

Constructors

SnapshotUpgrader(ISnapshotSerializer)

Initializes a new instance of the SnapshotUpgrader<TFrom, TTo> class.

protected SnapshotUpgrader(ISnapshotSerializer serializer)

Parameters

serializer ISnapshotSerializer

The serializer for snapshot data conversion.

Properties

AggregateType

Gets the aggregate type whose snapshots this upgrader handles.

public abstract string AggregateType { get; }

Property Value

string

The fully-qualified aggregate type name.

FromVersion

Gets the source version this upgrader upgrades from.

public abstract int FromVersion { get; }

Property Value

int

The source snapshot version.

ToVersion

Gets the target version this upgrader upgrades to.

public abstract int ToVersion { get; }

Property Value

int

The target snapshot version.

Methods

CanUpgrade(string, int)

Determines whether this upgrader can upgrade snapshots for the specified aggregate type and version.

public bool CanUpgrade(string aggregateType, int fromVersion)

Parameters

aggregateType string

The type of the aggregate.

fromVersion int

The snapshot version to upgrade from.

Returns

bool

True if this upgrader can handle the upgrade, otherwise false.

Upgrade(byte[])

Upgrades a snapshot from an older version to a newer version.

public byte[] Upgrade(byte[] oldSnapshotData)

Parameters

oldSnapshotData byte[]

The old snapshot data.

Returns

byte[]

The upgraded snapshot data.

UpgradeSnapshot(TFrom)

Upgrades a typed snapshot from the old version to the new version.

protected abstract TTo UpgradeSnapshot(TFrom oldSnapshot)

Parameters

oldSnapshot TFrom

The old snapshot data.

Returns

TTo

The upgraded snapshot data.