AggregateStateStorage<TValue extends Object, TState extends AggregateState<TValue>> class abstract

Base class for storing snapshots of AggregateState.

Snapshots are the representation of the current state at a certain "point in time", and it is an optimization that is considered and anti-pattern in general. Streams with many events indicates usually that the model is wrong. In general each stream should contain events from an aggregate instance (instance streams) only, which normally implies a small number of events in each stream. In such cases, it is better to just read all events and fold them onto the state. Snapshotting could be a good fit if the number of events are large though. For more on how to implement snapshotting, see Snapshotting strategies and Snapshots in Event sourcing.

Use settings to control snapshot behavior. Default is one snapshot each 1000 events (eager mode will produce a snapshot on first save, default false).

Override methods read and write to implement persistent storage. If in-memory caching is needed, AggregateStateStorageSettings.useCache must be true.

If onNew is not given, AggregateStateCreator must be registered with AggregateStateTypes.define, or method newInstance must be overridden (implements AggregateStateCreator as default method).

Implementers

Constructors

AggregateStateStorage({AggregateStateCreator<TValue, TState>? onNew, AggregateStateStorageSettings settings = AggregateStateStorageSettings.Default})
Default constructor.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
settings AggregateStateStorageSettings
Snapshot settings
final

Methods

contains(StreamName name) bool
Check if cache contains state for given name
invalidate() int
Invalidate in-memory cache of snapshots
load(StreamName name) Future<TState>
Load AggregateState of type TState for given StreamName.
newInstance([TValue? value, int? version]) → TState
Create new AggregateState instance with AggregateState.value of TValue. If value is not given, a default value is used.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(StreamName name) Future<AggregateStateSnapshotModel<TValue>?>
Read TState for given name from storage.
save(StreamName name, TState state) Future<void>
Save AggregateState of type TState for given StreamName.
shouldSnapshot(StreamName name, TState state) Future<bool>
Test if given state of stream name should be taken snapshot of
toString() String
A string representation of this object.
inherited
write(StreamName name, AggregateStateSnapshotModel<TValue> snapshot) Future<void>
Write snapshot of TState for given name to storage

Operators

operator ==(Object other) bool
The equality operator.
inherited