Skip to content

Pass transactions per call instead of storing them on DapperGateway - #57

Merged
twogood merged 1 commit into
mainfrom
dao-transactions
Oct 7, 2026
Merged

twogood merged 1 commit into
mainfrom
dao-transactions

Conversation

@twogood

@twogood twogood commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Replaces the settable DapperGateway.Transaction from #54, which had to be set and cleared by hand, could mismatch the gateway's connection, and wasn't reachable when the gateway was created inline (as in the README's DI example).

  • DAO methods take an IDbTransaction parameter. MethodHandler passes it to the gateway on SqlStatement.Transaction and doesn't bind it as a SQL parameter. Passing null means no transaction.
  • New IWithTransactions interface: DAO interfaces can extend it to call BeginTransaction(), so callers don't need the connection. Backed by the new IDatabaseGateway.BeginTransaction.
  • DapperGateway no longer stores any transaction.
public interface IUserDao : IWithTransactions
{
    [SqlUpdate("INSERT INTO user(id, name) VALUES (@id, @name)")]
    Task InsertNamed(int id, string name, IDbTransaction? transaction);
}

using var transaction = userDao.BeginTransaction();
await userDao.InsertNamed(42, "foobar", transaction);
transaction.Commit();

Breaking change compared with v5.0.0-rc3: the DapperGateway.Transaction property is removed, and IDatabaseGateway has a new member.

Tested: dotnet test (19 passed), including commit and rollback through the DAO on Sqlite.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for beginning database transactions through data access interfaces and explicitly associating transactions with individual statements.
    • Database operations can now run with or without a transaction, allowing changes to be committed or rolled back.
  • Documentation
    • Updated transaction examples to show how to begin a transaction, pass it to database operations, and commit it.

DAO methods take an IDbTransaction parameter, which MethodHandler passes
to the gateway on the SqlStatement. DAO interfaces can extend
IWithTransactions to begin transactions without access to the connection.
The gateway holds no transaction state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 563ee84f-ab32-4ee9-a9e5-f8c06c7d0e07
📥 Commits

Reviewing files that changed from the base of the PR and between a3802e2 and e94c84b.

📒 Files selected for processing (7)
  • Activout.DatabaseClient.Dapper/DapperGateway.cs
  • Activout.DatabaseClient.Test/DapperGatewayTransactionTest.cs
  • Activout.DatabaseClient/IDatabaseGateway.cs
  • Activout.DatabaseClient/IWithTransactions.cs
  • Activout.DatabaseClient/Implementation/DatabaseClient.cs
  • Activout.DatabaseClient/Implementation/MethodHandler.cs
  • README.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The database client now exposes transaction creation through DAO methods, carries an optional transaction on each SQL statement, and passes that transaction to Dapper execution. Transaction parameters are excluded from SQL parameter binding. Tests and README examples use the DAO-level transaction flow.

Changes

DAO Transaction Flow

Layer / File(s) Summary
Transaction creation contract and routing
Activout.DatabaseClient/IDatabaseGateway.cs, Activout.DatabaseClient/IWithTransactions.cs, Activout.DatabaseClient/Implementation/DatabaseClient.cs, Activout.DatabaseClient.Dapper/DapperGateway.cs
IDatabaseGateway and IWithTransactions expose transaction creation. DatabaseClient routes transaction interface methods to the gateway, and DapperGateway begins transactions on its connection.
Statement transaction propagation
Activout.DatabaseClient/Implementation/MethodHandler.cs, Activout.DatabaseClient.Dapper/DapperGateway.cs, Activout.DatabaseClient.Test/DapperGatewayTransactionTest.cs, README.md
MethodHandler assigns transaction arguments to SqlStatement.Transaction and excludes them from SQL parameters. DapperGateway passes that transaction to Dapper. Tests and documentation show the DAO transaction flow.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DAO
  participant DatabaseClient
  participant MethodHandler
  participant DapperGateway
  participant Dapper
  DAO->>DatabaseClient: BeginTransaction(isolationLevel)
  DatabaseClient->>DapperGateway: BeginTransaction(isolationLevel)
  DapperGateway-->>DAO: Return IDbTransaction
  DAO->>DatabaseClient: Invoke SQL method with transaction
  DatabaseClient->>MethodHandler: Invoke method handler
  MethodHandler->>DapperGateway: Send SqlStatement with transaction
  DapperGateway->>Dapper: Execute with statement transaction
  Dapper-->>DAO: Return result
Loading

Merge Risk: ⚪ Minimal · up to e94c8

This change moves transactions from gateway state to per-call parameters and adds a way to begin a transaction from a DAO. Commit and rollback are tested. The removal of the old gateway property is an intentional breaking change, and no merge-blocking risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 6 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing gateway-level transaction storage with per-call transaction passing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 6 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit begins a transaction with care,
Then passes it on with a hop and a hare.
The query runs gently, its rows in a row,
Commit keeps them near; rollback lets them go.
The rabbit thumps softly: “The flow’s clear to see!”

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Transaction forwarding is consistent across execution paths, with only optional single-row regression coverage remaining.

0 open findings

What changed in this PR

Replaces gateway-level transaction state with per-call transactions and lets DAOs begin transactions directly.

Changes:

  • Adds transaction creation through IWithTransactions.
  • Routes transaction arguments separately from SQL parameters.
  • Updates documentation and commit/rollback tests.
File Description
README.md Documents per-call transactions.
Activout.DatabaseClient/​IWithTransactions.cs Adds the DAO transaction interface.
Activout.DatabaseClient/​Implementation/​MethodHandler.cs Extracts transaction arguments from SQL parameters.
Activout.DatabaseClient/​Implementation/​DatabaseClient.cs Routes transaction creation to the gateway.
Activout.DatabaseClient/​IDatabaseGateway.cs Adds transaction creation and statement transaction data.
Activout.DatabaseClient.Test/​DapperGatewayTransactionTest.cs Tests DAO-driven commit and rollback.
Activout.DatabaseClient.Dapper/​DapperGateway.cs Forwards statement transactions to Dapper.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@twogood
twogood merged commit 64d6db6 into main Oct 7, 2026
8 checks passed
@twogood
twogood deleted the dao-transactions branch October 7, 2026 18:49
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.

2 participants