Table of Contents

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

sectionPath string

The configuration section path (e.g., "EventSourcing:Postgres").

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when sectionPath is 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

connectionString string

The Postgres connection string.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when connectionString is 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

name string

The connection string name in the ConnectionStrings section.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when name is 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

dataSource NpgsqlDataSource

The Npgsql data source.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentNullException

Thrown when dataSource is 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

dataSourceFactory Func<IServiceProvider, NpgsqlDataSource>

A factory receiving IServiceProvider and returning an Npgsql.NpgsqlDataSource.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentNullException

Thrown when dataSourceFactory is null.

EventStoreSchema(string)

Sets the schema name for event store tables. Default: "public".

IPostgresEventSourcingBuilder EventStoreSchema(string schema)

Parameters

schema string

The schema name.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when schema is null or whitespace.

EventStoreTable(string)

Sets the event store table name. Default: "events".

IPostgresEventSourcingBuilder EventStoreTable(string tableName)

Parameters

tableName string

The table name.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when tableName is 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

resolver IJsonTypeInfoResolver

The 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 resolver is null.

SnapshotStoreSchema(string)

Sets the schema name for snapshot store tables. Default: "public".

IPostgresEventSourcingBuilder SnapshotStoreSchema(string schema)

Parameters

schema string

The schema name.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when schema is null or whitespace.

SnapshotStoreTable(string)

Sets the snapshot store table name. Default: "event_store_snapshots".

IPostgresEventSourcingBuilder SnapshotStoreTable(string tableName)

Parameters

tableName string

The table name.

Returns

IPostgresEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when tableName is null or whitespace.