API reference — Projections
Nuvora.Nexus.Relay.Projections.EfCore
EF Core (PostgreSQL) projection checkpoint store for Nuvora Nexus Relay
dotnet add package Nuvora.Nexus.Relay.Projections.EfCore
Nuvora.Nexus.Relay.Projections.EfCore
CheckpointRecord
public class CheckpointRecord
Persistence row for a projection checkpoint in the relay_projection_checkpoints table.
Properties
DateTimeOffset UpdatedAt { get; set; }
Guid Id { get; set; }
Surrogate primary key. The logical key is the unique (projection_name, tenant_id) index — a surrogate is used so tenant_id can stay nullable (null = global) for RLS consistency, which a composite primary key could not express.
Guid? TenantId { get; set; }
Owning tenant (null = global). Under per-tenant projections each tenant keeps its own checkpoint per projection; this column carries that ownership (the per-tenant checkpoint keying lands with the projection tenant loop).
long CheckpointTxId { get; set; }
Inserting transaction id of the last processed event (the cursor’s TxId). Combined with CheckpointRecord.Position it forms the gap-safe resume cursor; stored separately so the host resumes on (tx_id, position) ordering rather than position alone.
long Position { get; set; }
string ProjectionName { get; set; }
EfCoreCheckpointStore
public sealed class EfCoreCheckpointStore : ICheckpointStore
EF Core checkpoint store. Uses the shared scoped context (via IRelayDbContextAccessor) so a checkpoint advance commits together with the projection’s read-model writes in that scope.
Constructors
EfCoreCheckpointStore(IRelayDbContextAccessor contextAccessor)
Methods
Task SaveAsync(string projectionName, EventCursor cursor, Guid? tenantId = null, CancellationToken cancellationToken = default(CancellationToken))
Persists the last processed cursor for a projection within a tenant (null = global).
Task<EventCursor> GetAsync(string projectionName, Guid? tenantId = null, CancellationToken cancellationToken = default(CancellationToken))
Returns the last processed cursor for a projection within a tenant (null = global), or EventCursor.Start if none.
EfCoreProjectionDeadLetterStore
public sealed class EfCoreProjectionDeadLetterStore : IProjectionDeadLetterStore
EF Core dead-letter store. EfCoreProjectionDeadLetterStore.AddAsync stages on the shared scoped context (via IRelayDbContextAccessor) so a dead letter commits in the SAME transaction as the checkpoint advance that skipped the poison event — the skip and its durable record are atomic.
Constructors
EfCoreProjectionDeadLetterStore(IRelayDbContextAccessor contextAccessor)
Methods
Task AddAsync(ProjectionDeadLetter deadLetter, CancellationToken cancellationToken = default(CancellationToken))
Stages a dead letter; the surrounding unit of work commits it. Idempotent on (projection name, global position).
Task<IReadOnlyList<ProjectionDeadLetter>> GetAsync(string? projectionName = null, int maxCount = 100, CancellationToken cancellationToken = default(CancellationToken))
Returns dead letters, newest first, optionally filtered to one projection.
Task<ProjectionDeadLetter?> FindAsync(string projectionName, long globalPosition, CancellationToken cancellationToken = default(CancellationToken))
Returns the dead letter for the (projection, position) key, or null.
Task<bool> RemoveAsync(string projectionName, long globalPosition, CancellationToken cancellationToken = default(CancellationToken))
Stages removal of a dead letter (after a successful replay); the surrounding unit of work commits it. Returns false when no such dead letter exists.
EfCoreProjectionFailureStore<TContext>
public sealed class EfCoreProjectionFailureStore<TContext> : IProjectionFailureStore where TContext : DbContext
EF Core (PostgreSQL) IProjectionFailureStore. Every operation runs on a short-lived context from the IDbContextFactory — never the shared scoped command context — because failure tallies must survive the batch transaction’s rollback (the rollback IS the failure being counted). The increment is a single atomic upsert, so concurrent host instances recording the same poison event never lose counts.
Constructors
EfCoreProjectionFailureStore(IDbContextFactory<TContext> contextFactory)
Methods
Task ClearAsync(string projectionName, long position, CancellationToken cancellationToken = default(CancellationToken))
Removes the failure record for an event that finally succeeded or was skipped as poison.
Task ClearProjectionAsync(string projectionName, CancellationToken cancellationToken = default(CancellationToken))
Removes all durable failure tallies for a projection. Used by a reset/rebuild so the poison budget starts clean and events previously skipped as poison are re-applied rather than re-skipped.
Task<IReadOnlyDictionary<long, ProjectionFailure>> GetFailuresAsync(string projectionName, long fromPosition, long toPosition, CancellationToken cancellationToken = default(CancellationToken))
Returns the recorded failures for one projection within an inclusive global-position range (the positions of the batch about to be applied), keyed by position.
Task<int> RecordFailureAsync(string projectionName, long position, string error, CancellationToken cancellationToken = default(CancellationToken))
Increments (upserting) the failure count for the event and returns the new count. Committed immediately on an independent connection.
EfCoreProjectionRebuildStore<TContext>
public sealed class EfCoreProjectionRebuildStore<TContext> : IProjectionRebuildStore where TContext : DbContext
EF Core rebuild store. Uses an IDbContextFactory (its own connection, independent of any projection batch transaction) so rebuild progress is observable across instances and survives restarts — mirroring the durable failure store.
Constructors
EfCoreProjectionRebuildStore(IDbContextFactory<TContext> contextFactory)
Methods
Task SetStatusAsync(string projectionName, Guid? tenant, ProjectionRebuildStatus status, string? error = null, CancellationToken cancellationToken = default(CancellationToken))
Task StartAsync(string projectionName, Guid? tenant, RebuildMode mode, long targetPosition, CancellationToken cancellationToken = default(CancellationToken))
Task<IReadOnlyList<ProjectionRebuild>> ListAsync(CancellationToken cancellationToken = default(CancellationToken))
Task<ProjectionRebuild?> GetAsync(string projectionName, Guid? tenant, CancellationToken cancellationToken = default(CancellationToken))
PostgresProjectionCoordinator
public sealed class PostgresProjectionCoordinator : IProjectionCoordinator
IProjectionCoordinator backed by PostgreSQL transaction-scoped advisory locks. Runs on the shared scoped DbContext (via IRelayDbContextAccessor), so the lock is taken on the same connection/transaction the projection host (or reset) is using and is released automatically when that transaction commits or rolls back — including if the holding instance dies.
Constructors
PostgresProjectionCoordinator(IRelayDbContextAccessor contextAccessor)
Methods
Task AcquireAsync(string projectionName, CancellationToken cancellationToken = default(CancellationToken))
Blocking acquisition of the projection’s processing lock within the current transaction; waits until any in-flight batch on another instance completes. Used by administrative operations (e.g. reset) that must not race the host.
Task<bool> TryAcquireAsync(string projectionName, CancellationToken cancellationToken = default(CancellationToken))
Non-blocking attempt to take the projection’s processing lock within the current transaction. Returns false if another instance currently holds it (the caller should skip this cycle).
ProjectionDeadLetterRecord
public class ProjectionDeadLetterRecord
Persistence row for a skipped poison event in the relay_projection_dead_letters table. Primary key is (ProjectionDeadLetterRecord.ProjectionName, ProjectionDeadLetterRecord.GlobalPosition).
Properties
DateTimeOffset OccurredAt { get; set; }
Guid? TenantId { get; set; }
Owning tenant (null = global).
long GlobalPosition { get; set; }
string Error { get; set; }
The failure that made the event poison.
string EventType { get; set; }
string Payload { get; set; }
Raw serialized event payload (stored as jsonb).
string ProjectionName { get; set; }
ProjectionFailureRecord
public sealed class ProjectionFailureRecord
Row of relay_projection_failures: the durable consecutive-failure tally for one event in one projection (see IProjectionFailureStore). Rows exist only while an event is failing — they are deleted when the event finally applies or is skipped as poison.
Properties
DateTimeOffset LastFailedAt { get; set; }
Guid? TenantId { get; set; }
Owning tenant (null = global).
int FailureCount { get; set; }
long Position { get; set; }
string LastError { get; set; }
string ProjectionName { get; set; }
ProjectionRebuildRecord
public sealed class ProjectionRebuildRecord
EF entity for the relay_projection_rebuilds table (one row per (projection, tenant)).
Properties
DateTimeOffset StartedAt { get; set; }
DateTimeOffset UpdatedAt { get; set; }
Guid TenantId { get; set; }
Owning tenant; Guid.Empty represents the global stream (no tenant).
int Mode { get; set; }
int Status { get; set; }
long TargetPosition { get; set; }
string ProjectionName { get; set; }
string? Error { get; set; }
Nuvora.Nexus.Relay.Projections.EfCore.DependencyInjection
CheckpointServiceCollectionExtensions
public static class CheckpointServiceCollectionExtensions
Registration helpers for the EF Core projection checkpoint store.
Methods
static IServiceCollection AddRelayProjectionCheckpointsEfCore(this IServiceCollection services)
Registers the EF Core checkpoint store and the projection dead-letter store. Relies on the event-store accessor being registered (via AddRelayEventStoreEfCore) and the host context calling ApplyRelayProjectionCheckpoints() in OnModelCreating (which also maps the dead-letter table).
static IServiceCollection AddRelayProjectionCheckpointsEfCore<TContext>(this IServiceCollection services)
As CheckpointServiceCollectionExtensions.AddRelayProjectionCheckpointsEfCore, additionally registering the durable IProjectionFailureStore bound to TContext’s IDbContextFactory (register one via AddDbContextFactory<TContext>). With it, poison-event retry budgets survive host restarts and are shared across instances instead of being per-process and in-memory.
static IServiceCollection AddRelayProjectionCoordinationPostgres(this IServiceCollection services)
Registers the PostgreSQL advisory-lock IProjectionCoordinator, which makes running multiple projection host instances safe (active/active with per-projection mutual exclusion). Add this on every instance when scaling the projection host out.
RebuildServiceCollectionExtensions
public static class RebuildServiceCollectionExtensions
Registration helpers for the EF Core projection rebuild store.
Methods
static IServiceCollection AddRelayProjectionRebuildEfCore<TContext>(this IServiceCollection services)
Registers the durable EF Core IProjectionRebuildStore bound to TContext’s IDbContextFactory (register one via AddDbContextFactory<TContext>), and the IProjectionRebuildManager. Map the table with ApplyRelayProjectionRebuilds() in OnModelCreating.
Nuvora.Nexus.Relay.Projections.EfCore.Persistence
CheckpointModelBuilderExtensions
public static class CheckpointModelBuilderExtensions
Maps the projection checkpoint table (relay_projection_checkpoints) and the projection dead-letter table (relay_projection_dead_letters) onto the host context.
Methods
static ModelBuilder ApplyRelayProjectionCheckpoints(this ModelBuilder modelBuilder)
static ModelBuilder ApplyRelayProjectionDeadLetters(this ModelBuilder modelBuilder)
Maps the projection dead-letter table. Applied automatically by CheckpointModelBuilderExtensions.ApplyRelayProjectionCheckpoints; exposed separately for hosts that manage their model piecemeal.
static ModelBuilder ApplyRelayProjectionFailures(this ModelBuilder modelBuilder)
Maps the durable projection failure-tally table (relay_projection_failures) used to make poison-event retry budgets restart-proof and instance-global. Applied automatically by CheckpointModelBuilderExtensions.ApplyRelayProjectionCheckpoints.
RebuildModelBuilderExtensions
public static class RebuildModelBuilderExtensions
Maps the projection rebuild table (relay_projection_rebuilds) onto the host context.
Methods
static ModelBuilder ApplyRelayProjectionRebuilds(this ModelBuilder modelBuilder)