Class ReadModelRestoreServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.EventSourcing.EntityFrameworkCore.dll
Registration of the PostgreSQL preservation that lets a failed replay restore the read models.
public static class ReadModelRestoreServiceCollectionExtensions
- Inheritance
-
ReadModelRestoreServiceCollectionExtensions
- Inherited Members
Methods
AddReadModelRestore<TReadContext>(IServiceCollection, Action<ReadModelRestoreOptions>?)
Keeps the read models a replay is about to empty, so a replay that fails — or whose host stops — leaves the read store as it was before the replay began, instead of empty or half rebuilt. PostgreSQL only.
public static IServiceCollection AddReadModelRestore<TReadContext>(this IServiceCollection services, Action<ReadModelRestoreOptions>? configure = null) where TReadContext : DbContext, IReadDbContext
Parameters
servicesIServiceCollectionThe service collection.
configureAction<ReadModelRestoreOptions>Adjusts the settings after the configuration section is applied.
Returns
- IServiceCollection
The same service collection for chaining.
Type Parameters
TReadContextThe read context whose tables a replay empties.
Examples
builder.Services
.AddNpgsqlReadDbContextFactory<AppReadDbContext>()
.AddReadModelRestore<AppReadDbContext>();
Remarks
Before a replay empties anything, every table TReadContext maps — the read models, the
projection checkpoints and the record of forgotten tenants among them — is copied into a schema of its own
(Schema) as one consistent snapshot. A replay that fails writes the copy back
in one transaction; one that succeeds drops it; one whose host stops leaves it, and the next host that starts
writes it back. Readers still see the rebuild in progress while it runs.
The copy costs the time to read the read store once more before the replay starts, and the disk to hold it twice
while the replay runs. Tables the host's view truncator empties but the context does not map are covered through
AdditionalTables; mapped tables a replay leaves alone are left out through
ExcludedTables. Settings are read from the ProjectionReplay:Restore
section. Requires a registered IDbContextFactory<TContext> for TReadContext;
a preservation registered before this call is kept.