Skip to content

✨feat: Add CancellationToken support to all async methods#18

Merged
lukaferlez merged 3 commits into
lukaferlez:masterfrom
filipklaric:feature/cancellation-token-support
Apr 1, 2026
Merged

✨feat: Add CancellationToken support to all async methods#18
lukaferlez merged 3 commits into
lukaferlez:masterfrom
filipklaric:feature/cancellation-token-support

Conversation

@filipklaric
Copy link
Copy Markdown
Contributor

@filipklaric filipklaric commented Mar 31, 2026

Body:

Summary

  • Added CancellationToken cancellationToken = default parameter to every async method across all interfaces (IAdd, IDelete, IUpdate, IUpsert, IReplace, IQueryGet, IQueryList, IQueryExist,
    IAggregate) and their Db-layer counterparts (IAddDb, IDeleteDb, etc.)
  • Threaded the token through the entire call chain down to Dapper using CommandDefinition — the only way to pass a cancellation token in Dapper 2.0.x
  • Updated DbConnectionExtensions, DbRepository, Entity, ProjectedEntity, BulkExtensions, MergeExtensions, OutputMapExtensions, TruncateExtensions, and SqlConnectionExtensions to forward the
    token at every level
  • Reflection-based tuple dispatch in Entity.ListAsync<T> updated to include CancellationToken in the method lookup type array and invocation arguments

Tests

  • Added CancellationTokenTests with 8 tests verifying that passing a pre-cancelled CancellationToken(canceled: true) causes OperationCanceledException for: ListAsync, GetAsync, AddAsync,
    UpdateAsync, DeleteAsync, ExistsAsync, DbRepository.QueryAsync, DbRepository.ExecuteAsync

Test plan

  • Run CancellationTokenTests against a SQL Server instance to confirm all 8 tests pass
  • Run existing test suite to confirm no regressions

filipklaric-lgtm and others added 3 commits March 31, 2026 09:57
Thread CancellationToken through the entire call chain from public interfaces down to Dapper CommandDefinition. All async operations now accept an optional cancellationToken parameter (default: default) and honour cancellation. Adds tests verifying that a pre-cancelled token throws OperationCanceledException.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Dapper.Contrib's DeleteAsync does not support CancellationToken.
The single-model delete overloads always route to Dapper.Contrib
and can never honour the token, so the parameter is removed.
IEnumerable and filter-based delete variants are unaffected as
they use bulk operations (SqlRepository path) that do support it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Downgrade Microsoft.Data.SqlClient from 7.0.0 to 5.2.2 — v7 dropped
.NET 6.0 support, causing SqlConnection.get_State() to throw
NullReferenceException on the test project's net6.0 target.

Forward CancellationToken through the entire BulkExtensions call chain:
InsertBulkAsync/UpdateBulkAsync/DeleteBulkAsync -> ExecuteAsync<T,R>
-> BulkSourceAsync -> TransferBulkAsync -> CreateTemporaryTableFromTable
and ExecuteWithOutputMapAsync. Previously the token was accepted in
every signature but silently dropped before reaching any Dapper
CommandDefinition, so pre-cancelled tokens had no effect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lukaferlez
Copy link
Copy Markdown
Owner

LGTM

@lukaferlez lukaferlez merged commit 013a909 into lukaferlez:master Apr 1, 2026
1 check passed
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.

3 participants