Skip to content

fix(persistence): make AmbientDbTransactionRegistry actually receive transaction events - #1393

Merged
iammukeshm merged 1 commit into
mainfrom
fix/ambient-transaction-registry-signatures
Sep 25, 2026
Merged

iammukeshm merged 1 commit into
mainfrom
fix/ambient-transaction-registry-signatures

Conversation

@iammukeshm

Copy link
Copy Markdown
Member

Extracted from #1374 (credit @maxiar, co-author on the commit) so it can ship without the SQL Server provider.

Bug

AmbientDbTransactionRegistry (the interceptor that lets the outbox write enlist in the business transaction) declared TransactionStarted / TransactionUsed with signatures that don't match IDbTransactionInterceptor, and had no async hooks. The interface gives every member a default no-op, so the methods compiled but were never called: the registry was always empty.

It's invisible on PostgreSQL because Npgsql runs commands in the connection's open transaction anyway. Any provider that needs the transaction set explicitly (e.g. SQL Server) would fail.

Fix

  • Every sync and async hook, with exact signatures.
  • Forget also matches by identity (a disposed transaction reports a null Connection).
  • AmbientDbTransactionRegistryTests uses the interface map to fail if any hook falls through to the default again. It fails on main and passes here.

Verification

Framework.Tests 202/202. Full Integration.Tests 753/753 and Middleware 5/5, so the outbox paths behave the same on Postgres with the registry populated. Build: 0 warnings.

Touches src/BuildingBlocks/Persistence (maintainer-approved).

🤖 Generated with Claude Code

…transaction events

Its TransactionStarted/TransactionUsed signatures did not match
IDbTransactionInterceptor, and the async hooks were missing. The interface
supplies default no-ops for every member, so the near-miss methods compiled
but were never called: the registry stayed empty and the outbox never
enlisted explicitly in the business transaction. Invisible on PostgreSQL
(Npgsql runs commands in the connection's open transaction anyway).

Implements every sync and async hook with the exact signatures, forgets
disposed transactions by identity, and adds a reflection test that fails if
any hook falls through to the interface default again.

Extracted from #1374.

Co-authored-by: maxiar <edujimenez86@hotmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@iammukeshm
iammukeshm merged commit d02a50b into main Sep 25, 2026
16 checks passed
@iammukeshm
iammukeshm deleted the fix/ambient-transaction-registry-signatures branch September 25, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant