Class Snapshot
Default implementation of ISnapshot.
public sealed record Snapshot : ISnapshot, IEquatable<Snapshot>
- Inheritance
-
Snapshot
- Implements
- Inherited Members
Remarks
Provides a record-based immutable implementation of the snapshot interface, suitable for most event sourcing scenarios.
Properties
AggregateId
Gets the aggregate identifier this snapshot belongs to.
public required string AggregateId { get; init; }
Property Value
- string
The aggregate identifier this snapshot belongs to.
AggregateType
Gets the type of the aggregate for deserialization.
public required string AggregateType { get; init; }
Property Value
- string
The type of the aggregate for deserialization.
CreatedAt
Gets the timestamp when this snapshot was created.
public required DateTimeOffset CreatedAt { get; init; }
Property Value
- DateTimeOffset
The timestamp when this snapshot was created.
Data
Gets the serialized state data.
public required ReadOnlyMemory<byte> Data { get; init; }
Property Value
- ReadOnlyMemory<byte>
The serialized state data as an immutable memory region.
Metadata
Gets optional metadata about the snapshot.
public IDictionary<string, object>? Metadata { get; init; }
Property Value
- IDictionary<string, object>
Optional metadata about the snapshot.
SnapshotId
Gets the unique identifier for this snapshot.
public required string SnapshotId { get; init; }
Property Value
- string
The unique identifier for this snapshot.
TenantId
Gets the tenant this snapshot belongs to, when the host is multi-tenant.
public string? TenantId { get; init; }
Property Value
Remarks
A snapshot is identified by its aggregate, and two tenants can hold the same aggregate identifier. Without a tenant the identity is ambiguous: one tenant's snapshot can be served to another, and a store keyed only on the aggregate cannot hold both at once. This is that discriminator.
Required, deliberately, and NOT defaulted to null. A default would let every implementation inherit "no tenant" without stating it, so a store that never considered tenancy would be indistinguishable from one that considered it and correctly reported none. Requiring the member forces each implementation to answer the question; forgetting is a compile error rather than a silent single-tenant assumption.
null means single-tenant — the correct value for a host that is not multi-tenant. It does not mean "unknown".
Version
Gets the version of the aggregate when this snapshot was created.
public required long Version { get; init; }
Property Value
- long
The version of the aggregate when this snapshot was created.
Methods
Create(string, long, byte[], string, IDictionary<string, object>?)
Creates a new Snapshot with a generated identifier and current timestamp.
public static Snapshot Create(string aggregateId, long version, byte[] data, string aggregateType, IDictionary<string, object>? metadata = null)
Parameters
aggregateIdstringThe aggregate identifier.
versionlongThe aggregate version.
databyte[]The serialized state data as an immutable memory region.
aggregateTypestringThe type of the aggregate.
metadataIDictionary<string, object>Optional metadata.