Class SqlServerOperationExecutor
- Namespace
- Excalibur.EventSourcing.SqlServer
- Assembly
- Excalibur.EventSourcing.SqlServer.dll
Deduplicates a single SQL event append using a receipt committed in its append transaction.
public sealed class SqlServerOperationExecutor : ISqlServerOperationExecutor
- Inheritance
-
SqlServerOperationExecutor
- Implements
- Inherited Members
Remarks
Apply Scripts/006_CreateOperationReceipts.sql first (adapt names for a custom events table). The callback may perform one nonempty append through SqlServerEventStore to this exact destination and tenant. It must not perform independently committed business writes or external effects. No-event callbacks are not recorded. Receipts are retained indefinitely. Concurrent callbacks may run; the unique receipt in the append transaction permits only one committed append.
Constructors
SqlServerOperationExecutor(Func<SqlConnection>, ITenantContext)
Initializes an executor using the event store's canonical schema and table names.
public SqlServerOperationExecutor(Func<SqlConnection> connectionFactory, ITenantContext tenantContext)
Parameters
connectionFactoryFunc<SqlConnection>Creates fresh owned primary SQL connections.
tenantContextITenantContextThe event store's tenant context.
SqlServerOperationExecutor(Func<SqlConnection>, ITenantContext, string, string)
Initializes an executor for the same primary database and names as the event store.
public SqlServerOperationExecutor(Func<SqlConnection> connectionFactory, ITenantContext tenantContext, string schema, string eventsTable)
Parameters
connectionFactoryFunc<SqlConnection>Creates fresh owned primary SQL connections.
tenantContextITenantContextThe event store's tenant context.
schemastringThe event store schema.
eventsTablestringThe event table; receipts use this name followed by Operations.
Methods
BindSourceAsync(string, ReadOnlyMemory<byte>, CancellationToken)
Binds a configured source to its database/capture generation, refusing silent history replacement.
[SuppressMessage("Security", "CA2100", Justification = "Only constructor-validated SQL identifiers are interpolated; source and identity are typed parameters.")]
public Task BindSourceAsync(string source, ReadOnlyMemory<byte> sourceIdentity, CancellationToken cancellationToken)
Parameters
sourcestringStable configured source name; do not include its changing generation.
sourceIdentityReadOnlyMemory<byte>SHA-256 of database identity, recovery fork and capture creation identity.
cancellationTokenCancellationTokenCancels the check.
Returns
Remarks
Store this binding outside databases refreshed from source backups. Check before each delivery and on startup. A mismatch requires operator-coordinated reconciliation or rebuild before explicit rebind. This check is not a fence against an administrator forcing a restore during an in-flight handler; maintenance must stop and drain all consumers before replacing the source.
ExecuteAsync(string, string, ReadOnlyMemory<byte>, Func<CancellationToken, Task>, CancellationToken)
Runs a single-append operation or returns its original durable receipt without running it.
public Task<SqlServerOperationResult> ExecuteAsync(string scope, string operationKey, ReadOnlyMemory<byte> fingerprint, Func<CancellationToken, Task> action, CancellationToken cancellationToken)
Parameters
scopestringA stable authenticated caller and operation namespace, or CDC source incarnation.
operationKeystringThe caller's stable retry key. Compared ordinally.
fingerprintReadOnlyMemory<byte>SHA-256 of immutable input, including target and original preconditions.
actionFunc<CancellationToken, Task>The handler. At most one nonempty event append is supported.
cancellationTokenCancellationTokenCancels this attempt; cancellation does not prove rollback.
Returns
- Task<SqlServerOperationResult>
The original receipt on replay, or the outcome of this attempt.