Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add CommandDefinition.SetCommandSetup for configuring commands after Dapper setup#2186

Open
toreamun wants to merge 1 commit intoDapperLib:mainDapperLib/Dapper:mainfrom
toreamun:feature/set-command-setuptoreamun/Dapper:feature/set-command-setupCopy head branch name to clipboard
Open

Add CommandDefinition.SetCommandSetup for configuring commands after Dapper setup#2186
toreamun wants to merge 1 commit intoDapperLib:mainDapperLib/Dapper:mainfrom
toreamun:feature/set-command-setuptoreamun/Dapper:feature/set-command-setupCopy head branch name to clipboard

Conversation

@toreamun
Copy link

This PR adds a simple, non-invasive extension point to configure IDbCommand instances after Dapper has completed its own setup.

Motivation

Applications communicating with cloud services need to handle transient faults. Microsoft.Data.SqlClient provides built-in Configurable retry logic, but while retry logic can be configured at the connection level (for Open() etc.), command-level retry requires setting SqlCommand.RetryLogicProvider on each command.

The current version of Dapper doesn't provide a way to configure provider-specific command properties like RetryLogicProvider.

Solution

This PR adds a minimal API:

public static void SetCommandSetup(Action<IDbCommand>? setup)

The callback is invoked at the end of internal SetupCommand, after Dapper has configured the command.

Usage example

// Configure once at application startup
var retryProvider = SqlConfigurableRetryFactory.CreateExponentialRetryProvider(new SqlRetryLogicOption());

CommandDefinition.SetCommandSetup(cmd =>
{
    if (cmd is SqlCommand sqlCmd)
        sqlCmd.RetryLogicProvider = retryProvider;
});

// All subsequent Dapper calls will have retry logic configured
connection.Query<int>("SELECT 1");

Why this approach?

  • Minimal API surface - Single static method, follows existing patterns like SqlMapper.SetTypeMap
  • Non-invasive - No changes to CommandDefinition constructor or public properties
  • Database-agnostic - Dapper remains provider-independent; the callback handles provider-specific logic
  • Zero overhead when not used - Simple null check

Related issues

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.