Add the projection persistence and the two services around it:
- Projection.ReadModel: a shared EF Core (Npgsql) read model owning the projection
schema — register_projection + the subscriber's processed_notifications log — plus
EfProjectionStore / EfNotificationLog (atomic record-or-skip on the PK for idempotency)
and the initial migration. One rebuildable store, written by the subscriber and read
by projection-api (ADR-0008).
- EventSubscriber.Api: POST /notifications NRC callback (enforces the abonnement bearer,
401 without it per ADR-0007), POST /admin/rebuild, /health. Migrates on start.
- ProjectionApi.Api: GET /register, GET /register/{id}, /health — the read side.
dotnet-ef pinned as a local tool for migrations; NuGetAuditMode=direct so EF's
design-time-only tooling transitive doesn't flag the shipped build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.4 KiB
C#
31 lines
1.4 KiB
C#
using EventSubscriber.Application;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Projection.ReadModel;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>Register the projection <see cref="ProjectionDbContext"/> against Postgres.</summary>
|
|
public static IServiceCollection AddProjectionReadModel(this IServiceCollection services, string connectionString)
|
|
=> services.AddDbContext<ProjectionDbContext>(o => o.UseNpgsql(connectionString));
|
|
|
|
/// <summary>Register the write-side ports (projector store + notification log) used by the Event Subscriber.</summary>
|
|
public static IServiceCollection AddProjectionWriteSide(this IServiceCollection services)
|
|
{
|
|
services.AddScoped<IProjectionStore, EfProjectionStore>();
|
|
services.AddScoped<INotificationLog, EfNotificationLog>();
|
|
services.AddScoped<NotificationProjector>();
|
|
return services;
|
|
}
|
|
|
|
/// <summary>Apply any pending EF migrations. Called once on service start so a fresh stack
|
|
/// reaches a usable schema without a manual migration step (DoD: compose up reaches green).</summary>
|
|
public static async Task MigrateProjectionAsync(this IServiceProvider services, CancellationToken ct = default)
|
|
{
|
|
await using var scope = services.CreateAsyncScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<ProjectionDbContext>();
|
|
await db.Database.MigrateAsync(ct);
|
|
}
|
|
}
|