Table of Contents

Interface ISqlServerEventSourcingBuilder

Namespace
Excalibur.EventSourcing.SqlServer
Assembly
Excalibur.EventSourcing.SqlServer.dll

Fluent builder interface for configuring SQL Server event sourcing settings.

public interface ISqlServerEventSourcingBuilder

Remarks

Provides the canonical 4 connection overloads, an explicit owned-primary factory opt-in, and subsystem-specific configuration for event store and snapshot store schemas and tables. Follows the builder pattern established by ISqlServerCdcConnectionBuilder.

Connection overloads are mutually exclusive (last-wins): If multiple connection methods are called, the last one takes effect. Each call overwrites any previously configured connection.

Usage:

services.AddExcalibur(x => x.AddEventSourcing(es =>
{
    es.UseSqlServer(sql =>
    {
        sql.ConnectionString("Server=...;Database=EventStore;...")
           .EventStoreSchema("es")
           .EventStoreTable("Events")
           .SnapshotStoreSchema("es")
           .SnapshotStoreTable("Snapshots");
    })
    .AddRepository<OrderAggregate, Guid>();
}));

Methods

BindConfiguration(string)

Binds options from an IConfiguration section.

ISqlServerEventSourcingBuilder BindConfiguration(string sectionPath)

Parameters

sectionPath string

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

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when sectionPath is null or whitespace.

ConnectionFactory(Func<IServiceProvider, Func<SqlConnection>>)

Sets a factory function that creates SQL connections. Use for Azure Managed Identity, Key Vault, or custom connection pooling.

ISqlServerEventSourcingBuilder ConnectionFactory(Func<IServiceProvider, Func<SqlConnection>> connectionFactory)

Parameters

connectionFactory Func<IServiceProvider, Func<SqlConnection>>

A factory receiving IServiceProvider and returning a Func<SqlConnection> that creates connections on demand.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentNullException

Thrown when connectionFactory is null.

ConnectionString(string)

Sets the SQL Server connection string.

ISqlServerEventSourcingBuilder ConnectionString(string connectionString)

Parameters

connectionString string

The SQL Server connection string.

Returns

ISqlServerEventSourcingBuilder

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.

ISqlServerEventSourcingBuilder ConnectionStringName(string name)

Parameters

name string

The connection string name in the ConnectionStrings section.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when name is null or whitespace.

EventStoreSchema(string)

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

ISqlServerEventSourcingBuilder EventStoreSchema(string schema)

Parameters

schema string

The schema name.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when schema is null or whitespace.

EventStoreTable(string)

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

ISqlServerEventSourcingBuilder EventStoreTable(string tableName)

Parameters

tableName string

The table name.

Returns

ISqlServerEventSourcingBuilder

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.

ISqlServerEventSourcingBuilder EventTypeInfoResolver(IJsonTypeInfoResolver resolver)

Parameters

resolver IJsonTypeInfoResolver

The application's event type-info resolver, typically a source-generated context.

Returns

ISqlServerEventSourcingBuilder

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.

OwnedPrimaryConnectionFactory(Func<IServiceProvider, Func<SqlConnection>>)

Configures a factory transferring fresh closed primary connections to the stores.

ISqlServerEventSourcingBuilder OwnedPrimaryConnectionFactory(Func<IServiceProvider, Func<SqlConnection>> connectionFactory)

Parameters

connectionFactory Func<IServiceProvider, Func<SqlConnection>>

Factory resolving the connection source once, then creating a new owned closed connection per invocation.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Remarks

Connections must target the same logical primary database without cached query results. The stores dispose them; never return a caller-owned connection. This opt-in enables independent authoritative event rechecks. Authentication is the factory's responsibility. Like other connection methods, the last call wins. Existing custom builders must implement this opt-in explicitly.

Exceptions

NotSupportedException

This builder does not implement the owned-primary contract.

SnapshotStoreSchema(string)

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

ISqlServerEventSourcingBuilder SnapshotStoreSchema(string schema)

Parameters

schema string

The schema name.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when schema is null or whitespace.

SnapshotStoreTable(string)

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

ISqlServerEventSourcingBuilder SnapshotStoreTable(string tableName)

Parameters

tableName string

The table name.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when tableName is null or whitespace.

UseMaterializedViewStore()

Enables SQL Server materialized view store registration, using the same connection configured for the event store.

ISqlServerEventSourcingBuilder UseMaterializedViewStore()

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Remarks

Registers IMaterializedViewStore backed by SqlServerMaterializedViewStore. Uses "MaterializedViews" and "MaterializedViewPositions" as default table names.

UseMaterializedViewStore(string, string, string)

Enables SQL Server materialized view store registration with custom table names.

ISqlServerEventSourcingBuilder UseMaterializedViewStore(string viewTableName, string positionTableName, string schemaName = "dbo")

Parameters

viewTableName string

The view data table name.

positionTableName string

The position tracking table name.

schemaName string

The schema holding both tables. Defaults to dbo, the same default the store resolves, so omitting it does not move the tables. Every statement the store runs names the schema explicitly, including the DDL it emits, so a schema set here is honoured rather than resolved through the caller's default schema.

Returns

ISqlServerEventSourcingBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when viewTableName, positionTableName or schemaName is null or whitespace.