Interface IEventStreamRepository
- Namespace
- Stratara.Abstractions.EventSourcing
- Assembly
- Stratara.Abstractions.dll
Low-level repository over the event_stream_entry table. Implementations live
in the EF Core write-store package; consumers typically go through
IEventSource instead of using this directly.
public interface IEventStreamRepository
- Extension Methods
Remarks
Every read returns every tenant's entries, whatever query filters the underlying context declares: a stream's version and owner are decided across all its entries, and the store is one history the framework reads on behalf of every tenant. Nothing here checks a stream's owner against the session; a handler that must refuse another tenant's stream checks the owner of the aggregate it loaded.
Methods
AddRangeAsync(IReadOnlyList<EventStreamEntry>, CancellationToken)
Appends entries to the underlying DbContext. Caller is responsible for the transactional save.
Task AddRangeAsync(IReadOnlyList<EventStreamEntry> eventEntries, CancellationToken cancellationToken = default)
Parameters
eventEntriesIReadOnlyList<EventStreamEntry>cancellationTokenCancellationToken
Returns
GetFirstOrDefaultAsync(Guid, CancellationToken)
Returns the first entry of the stream — typically the creation event.
Task<EventStreamEntry?> GetFirstOrDefaultAsync(Guid streamId, CancellationToken cancellationToken = default)
Parameters
streamIdGuidcancellationTokenCancellationToken
Returns
GetLastHashedEventAsync(CancellationToken)
Returns the most recent entry whose hash has been computed.
Task<EventStreamEntry?> GetLastHashedEventAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetManyAfterSequenceAsync(long, int, CancellationToken)
Returns up to batchSize entries with a sequence number greater than afterSequenceNumber.
Task<IReadOnlyList<EventStreamEntry>> GetManyAfterSequenceAsync(long afterSequenceNumber, int batchSize, CancellationToken cancellationToken = default)
Parameters
afterSequenceNumberlongbatchSizeintcancellationTokenCancellationToken
Returns
GetManyAfterSequenceInStreamOrderAsync(long, int, CancellationToken)
Returns the entries after afterSequenceNumber in the order a replay applies
them: each stream's entries in version order, and the streams interleaved as their sequence
numbers interleave them.
Task<IReadOnlyList<EventStreamEntry>> GetManyAfterSequenceInStreamOrderAsync(long afterSequenceNumber, int batchSize, CancellationToken cancellationToken = default)
Parameters
afterSequenceNumberlongThe sequence number the range starts after.
batchSizeintHow many entries the range holds at least, where the store has them.
cancellationTokenCancellationTokenCancels the read.
Returns
- Task<IReadOnlyList<EventStreamEntry>>
The range's entries in replay order; empty when no entry follows
afterSequenceNumber.
Remarks
A save does not number its entries in version order, so the sequence number alone can put a
stream's later version before its earlier one. The result covers every entry of a contiguous
range of sequence numbers — at least batchSize entries where the store holds
that many — and within the range each stream's entries take the places its sequence numbers
hold, in version order. The range is extended until no stream in it has an entry of a lower
version beyond it, so the result may hold more than batchSize entries.
The order holds for a walk of the store from its beginning: a first range that starts at
0, and each next one after the highest sequence number of the result before it. From any
other position — a checkpoint taken inside a result, or a walk that did not start at 0 — a
stream whose versions were numbered against their order on both sides of it can be returned out
of order.
The next range starts after the highest sequence number in the result, which is not necessarily that of its last entry. The default implementation returns GetManyAfterSequenceAsync(long, int, CancellationToken) — sequence order, which is version order only for a store that numbers its entries that way; an implementation overrides it to give the guarantee.
GetManyAsync(Guid, long?, long?, CancellationToken)
Returns entries of the stream filtered by version range, ascending by version.
Task<IReadOnlyList<EventStreamEntry>> GetManyAsync(Guid streamId, long? fromVersion = null, long? toVersion = null, CancellationToken cancellationToken = default)
Parameters
streamIdGuidfromVersionlong?toVersionlong?cancellationTokenCancellationToken
Returns
GetMaxSequenceNumberAsync(CancellationToken)
Returns the maximum sequence number across all streams.
Task<long> GetMaxSequenceNumberAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetPreviousEventAsync(long, CancellationToken)
Returns the entry immediately preceding sequenceNumber in stream order.
Task<EventStreamEntry?> GetPreviousEventAsync(long sequenceNumber, CancellationToken cancellationToken = default)
Parameters
sequenceNumberlongcancellationTokenCancellationToken
Returns
GetUnhashedEventsAsync(int, DateTimeOffset, CancellationToken)
Returns up to batchSize entries that have not yet been hashed and are older than cutoff.
Task<IReadOnlyList<EventStreamEntry>> GetUnhashedEventsAsync(int batchSize, DateTimeOffset cutoff, CancellationToken cancellationToken = default)
Parameters
batchSizeintcutoffDateTimeOffsetcancellationTokenCancellationToken
Returns
GetVersionOrDefaultAsync(Guid, CancellationToken)
Returns the head version of the stream, or 0 if it does not exist.
Task<long> GetVersionOrDefaultAsync(Guid streamId, CancellationToken cancellationToken = default)
Parameters
streamIdGuidcancellationTokenCancellationToken
Returns
StreamExistsAsync(Guid, CancellationToken)
Returns true if the stream has at least one entry.
Task<bool> StreamExistsAsync(Guid streamId, CancellationToken cancellationToken = default)
Parameters
streamIdGuidcancellationTokenCancellationToken
Returns
UpdateRange(IReadOnlyList<EventStreamEntry>)
Updates entries already tracked by the underlying DbContext.
void UpdateRange(IReadOnlyList<EventStreamEntry> eventEntries)
Parameters
eventEntriesIReadOnlyList<EventStreamEntry>