Class NpgsqlDbContextServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.EventSourcing.EntityFrameworkCore.dll
Service-collection extensions that register Npgsql-backed IDbContextFactory<TContext> instances for the Stratara write, read, and identity stores with snake_case naming, pgvector support, and a reduced connection-pool cap suitable for multi-tenant hosts.
public static class NpgsqlDbContextServiceCollectionExtensions
- Inheritance
-
NpgsqlDbContextServiceCollectionExtensions
- Inherited Members
Methods
AddNpgsqlIdentityDbContextFactory<TDbContext>(IServiceCollection)
Registers an Npgsql-backed IDbContextFactory<TContext> for an identity-store DbContext together with a scoped resolution of the context itself (so ASP.NET Identity can inject it directly) and the default IDbResolver.
public static IServiceCollection AddNpgsqlIdentityDbContextFactory<TDbContext>(this IServiceCollection services) where TDbContext : DbContext, IIdentityDbContext
Parameters
servicesIServiceCollectionThe service collection to add registrations to.
Returns
- IServiceCollection
The same IServiceCollection for chaining.
Type Parameters
TDbContextThe concrete identity-store DbContext type.
Examples
Also resolves the context itself as scoped, so ASP.NET Core Identity can inject it directly:
services.AddNpgsqlIdentityDbContextFactory<AppIdentityDbContext>();
AddNpgsqlReadDbContextFactory<TDbContext>(IServiceCollection)
Registers an Npgsql-backed IDbContextFactory<TContext> for a read-store DbContext together with the read-side unit of work over it, and the default IDbResolver if none has been registered yet.
public static IServiceCollection AddNpgsqlReadDbContextFactory<TDbContext>(this IServiceCollection services) where TDbContext : DbContext, IReadDbContext
Parameters
servicesIServiceCollectionThe service collection to add registrations to.
Returns
- IServiceCollection
The same IServiceCollection for chaining.
Type Parameters
TDbContextThe concrete read-store DbContext type.
Examples
services.AddNpgsqlReadDbContextFactory<AppReadDbContext>();
Remarks
The IProjectionsUnitOfWork that projections query and write through — and the
IReadUnitOfWork it derives from, resolving to the same scoped instance — is
registered here as ProjectionsUnitOfWork<TDbContext>. A host that registers its
own read-side unit of work, before or after this call, keeps it.
AddNpgsqlWriteDbContextFactory<TDbContext>(IServiceCollection)
Registers an Npgsql-backed IDbContextFactory<TContext> for a write-store DbContext together with the write-side unit of work over it, and the default IDbResolver if none has been registered yet.
public static IServiceCollection AddNpgsqlWriteDbContextFactory<TDbContext>(this IServiceCollection services) where TDbContext : DbContext, IWriteDbContext
Parameters
servicesIServiceCollectionThe service collection to add registrations to.
Returns
- IServiceCollection
The same IServiceCollection for chaining.
Type Parameters
TDbContextThe concrete write-store DbContext type.
Examples
Reads the connection string named defaultdb; with the session and security composites
in place, nothing else is needed for the store:
services.AddNpgsqlWriteDbContextFactory<AppWriteDbContext>();
Remarks
This binds the write store to the host: the IWriteUnitOfWork that the event
source, the outbox dispatcher and the command worker depend on is registered here, scoped,
as WriteUnitOfWork<TDbContext> over this context. A host that registers its own
IWriteUnitOfWork — before or after this call — keeps it.
The unit of work also takes the ambient ISessionContextProvider and the
ISecureJsonSerializer, which come from AddSessionContext() and
AddSecurity() — applied by every worker composite, and to be called explicitly by a
host that composes its own role. They are resolved when the unit of work is first used, so
the order of the Add* calls does not matter.