Interface IPostgresEventSourcingBuilder
- Namespace
- Excalibur.EventSourcing.Postgres
- Assembly
- Excalibur.EventSourcing.Postgres.dll
Fluent builder interface for configuring Postgres event sourcing settings.
public interface IPostgresEventSourcingBuilder
Remarks
Provides 5 canonical connection overloads (adds DataSource(NpgsqlDataSource) beyond the SQL Server pattern's 4) plus subsystem-specific configuration for event store and snapshot store schemas and tables.
Connection overloads are mutually exclusive (last-wins): If multiple connection methods are called, the last one takes effect.
All connection paths converge to Npgsql.NpgsqlDataSource: ConnectionString(string) and ConnectionStringName(string) create an Npgsql.NpgsqlDataSource internally for proper connection pooling.
Usage:
services.AddExcalibur(x => x.AddEventSourcing(es =>
{
es.UsePostgres(pg =>
{
pg.ConnectionString("Host=localhost;Database=EventStore;...")
.EventStoreSchema("public")
.EventStoreTable("events")
.SnapshotStoreSchema("public")
.SnapshotStoreTable("snapshots");
})
.AddRepository<OrderAggregate, Guid>();
}));
Methods
BindConfiguration(string)
Binds options from an IConfiguration section.
IPostgresEventSourcingBuilder BindConfiguration(string sectionPath)
Parameters
sectionPathstringThe configuration section path (e.g., "EventSourcing:Postgres").
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
sectionPathis null or whitespace.
ConnectionString(string)
Sets the Postgres connection string. An Npgsql.NpgsqlDataSource is created internally for proper connection pooling.
IPostgresEventSourcingBuilder ConnectionString(string connectionString)
Parameters
connectionStringstringThe Postgres connection string.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
connectionStringis null or whitespace.
ConnectionStringName(string)
Resolves the connection string from IConfiguration.GetConnectionString(name)
at service resolution time. An Npgsql.NpgsqlDataSource is created
internally for proper connection pooling.
IPostgresEventSourcingBuilder ConnectionStringName(string name)
Parameters
namestringThe connection string name in the
ConnectionStringssection.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
nameis null or whitespace.
DataSource(NpgsqlDataSource)
Sets a pre-configured Npgsql.NpgsqlDataSource directly. The consumer owns the lifecycle of the provided data source.
IPostgresEventSourcingBuilder DataSource(NpgsqlDataSource dataSource)
Parameters
dataSourceNpgsqlDataSourceThe Npgsql data source.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentNullException
Thrown when
dataSourceis null.
DataSourceFactory(Func<IServiceProvider, NpgsqlDataSource>)
Sets a factory function that creates an Npgsql.NpgsqlDataSource. Use for advanced scenarios like custom SSL, certificate auth, or dynamic configuration.
IPostgresEventSourcingBuilder DataSourceFactory(Func<IServiceProvider, NpgsqlDataSource> dataSourceFactory)
Parameters
dataSourceFactoryFunc<IServiceProvider, NpgsqlDataSource>A factory receiving IServiceProvider and returning an Npgsql.NpgsqlDataSource.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentNullException
Thrown when
dataSourceFactoryis null.
EventStoreSchema(string)
Sets the schema name for event store tables. Default: "public".
IPostgresEventSourcingBuilder EventStoreSchema(string schema)
Parameters
schemastringThe schema name.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
schemais null or whitespace.
EventStoreTable(string)
Sets the event store table name. Default: "events".
IPostgresEventSourcingBuilder EventStoreTable(string tableName)
Parameters
tableNamestringThe table name.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
tableNameis null or whitespace.
EventTypeInfoResolver(IJsonTypeInfoResolver)
Supplies a source-generated JSON type-info resolver covering the application's domain event types and the runtime types of the values it places in Metadata, so the event store serializes without reflection under trimming and native AOT.
IPostgresEventSourcingBuilder EventTypeInfoResolver(IJsonTypeInfoResolver resolver)
Parameters
resolverIJsonTypeInfoResolverThe application's event type-info resolver, typically a source-generated context.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Remarks
Domain events are consumer types the framework cannot source-generate, so with no resolver the store serializes them through the reflection-based serializer. That works under the JIT, but a native-AOT application published with reflection-based serialization disabled has no reflection path to fall back on and the first append fails. The stored wire format does not vary with this setting: the resolver supplies type metadata only, and the naming policy, string-enum representation and null handling remain the store's own.
Exceptions
- ArgumentNullException
Thrown when
resolveris null.
SnapshotStoreSchema(string)
Sets the schema name for snapshot store tables. Default: "public".
IPostgresEventSourcingBuilder SnapshotStoreSchema(string schema)
Parameters
schemastringThe schema name.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
schemais null or whitespace.
SnapshotStoreTable(string)
Sets the snapshot store table name. Default: "event_store_snapshots".
IPostgresEventSourcingBuilder SnapshotStoreTable(string tableName)
Parameters
tableNamestringThe table name.
Returns
- IPostgresEventSourcingBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
tableNameis null or whitespace.