When you load an aggregate with IDomainService.GetAggregate, you choose how it should be reconstructed. Memoria offers four read modes that trade off freshness against I/O and reconstruction cost.
| ReadMode | Reads snapshot | Applies new events after the snapshot | Reconstructs from events if no snapshot | Returns null when… |
|---|---|---|---|---|
SnapshotOnly (default) |
yes | no | no | no snapshot exists |
SnapshotWithNewEvents |
yes | yes | no | no snapshot exists |
SnapshotOrCreate |
yes | no | yes | no snapshot and no events |
SnapshotWithNewEventsOrCreate |
yes | yes | yes | no snapshot and no events |
Walk down the questions:
SnapshotOnly. Fastest path; one record fetched.SnapshotWithNewEvents. Reads snapshot + the tail of events to apply.SnapshotOrCreate. If a snapshot is missing, the aggregate is reconstructed from events and a fresh snapshot is stored.SnapshotWithNewEventsOrCreate. Safe default for “I don’t care how it got here, just give me the latest aggregate state.”SnapshotOrCreate and SnapshotWithNewEventsOrCreate will write a snapshot automatically the first time they reconstruct an aggregate from events. This is the supported way to introduce a new aggregate type, or to migrate to a changed aggregate structure — increase the aggregate version to force snapshot recreation.
SnapshotOnly and SnapshotWithNewEvents never write — they return null if the snapshot is missing, even when applicable events exist in the stream.
GetAggregate API