Table of Contents

Interface IAtomicMaterializedViewStore

Namespace
Excalibur.EventSourcing
Assembly
Excalibur.EventSourcing.Abstractions.dll

A IMaterializedViewStore that can persist a view and advance its processed position as one durable, all-or-nothing operation — the precondition for exactly-once projection.

public interface IAtomicMaterializedViewStore : IMaterializedViewStore
Inherited Members

Remarks

This capability is a separate type, not a virtual member on IMaterializedViewStore, because a store cannot honour it by inheriting a default. Writing the view and the position as two operations and crashing between them replays the event on restart, which double-counts any view that accumulates rather than overwrites. A store that has no way to commit both writes together must therefore be unable to express the guarantee at all, rather than silently inherit it.

Not every backing store can implement this. A store whose view and position live in different indices or collections with no cross-document transaction cannot commit both, and does not implement this interface. Such a store is rejected when a projection requiring exactly-once is wired to it, at startup.

Implementing this interface is necessary but not sufficient: a store whose atomicity depends on runtime configuration must report that configuration through SupportsAtomicWrites, so a deployment that disables it is refused at startup rather than degrading to at-least-once in production.

Properties

SupportsAtomicWrites

Gets a value indicating whether this store instance can currently perform atomic view+position writes.

bool SupportsAtomicWrites { get; }

Property Value

bool

true when SaveViewAndPositionAsync<TView>(string, string, TView, long, CancellationToken) commits both writes as one unit; otherwise false.

Remarks

Implementing the interface states the store is capable of atomic writes; this property states whether the current configuration enables them. A store whose atomicity is unconditional returns true constantly. A store whose atomicity requires an opt-in — a transaction mode, a replica set — returns the value of that setting, so the check reads the option that actually governs the behaviour rather than a proxy for it.

Methods

SaveViewAndPositionAsync<TView>(string, string, TView, long, CancellationToken)

Persists a view and advances the processed position for its view name in a single durable operation.

[RequiresUnreferencedCode("Implementations serialize the view type reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming.")]
[RequiresDynamicCode("Implementations serialize the view type reflectively; supply JsonSerializerOptions with a source-generated resolver for AOT.")]
ValueTask SaveViewAndPositionAsync<TView>(string viewName, string viewId, TView view, long position, CancellationToken cancellationToken) where TView : class

Parameters

viewName string

The logical view name the position belongs to.

viewId string

The identifier of the view instance being written.

view TView

The view to persist.

position long

The global stream position that produced view.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

Type Parameters

TView

The materialized view type.

Remarks

Both writes commit, or neither does. The position advance is monotonic: a lower position never overwrites a higher one, so a delayed or retried write cannot rewind the checkpoint and replay events that were already applied.

Exceptions

ArgumentException

viewName or viewId is null, empty, or white space.

ArgumentNullException

view is null.