diff --git a/Dapper/CommandDefinition.cs b/Dapper/CommandDefinition.cs
index 19963ba67..c019e88f3 100644
--- a/Dapper/CommandDefinition.cs
+++ b/Dapper/CommandDefinition.cs
@@ -16,6 +16,17 @@ internal static CommandDefinition ForCallback(object? parameters, CommandFlags f
return new CommandDefinition(parameters is DynamicParameters ? parameters : null, flags);
}
+ ///
+ /// Register a global callback to configure commands after Dapper has performed its own setup.
+ /// Useful for setting provider-specific properties like SqlCommand.RetryLogicProvider.
+ /// Pass null to remove any previously registered callback.
+ ///
+ /// The callback to invoke after command setup, or null to clear.
+ public static void SetCommandSetup(Action? setup)
+ {
+ commandSetup = setup;
+ }
+
internal void OnCompleted()
{
(Parameters as SqlMapper.IParameterCallbacks)?.OnCompleted();
@@ -136,11 +147,14 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action?
}
cmd.CommandType = CommandTypeDirect;
paramReader?.Invoke(cmd, Parameters);
+ commandSetup?.Invoke(cmd);
return cmd;
}
private static SqlMapper.Link>? commandInitCache;
+ private static Action? commandSetup;
+
internal static void ResetCommandInitCache()
=> SqlMapper.Link>.Clear(ref commandInitCache);
diff --git a/Dapper/PublicAPI/net461/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/net461/PublicAPI.Unshipped.txt
index 91b0e1a43..5a14caf54 100644
--- a/Dapper/PublicAPI/net461/PublicAPI.Unshipped.txt
+++ b/Dapper/PublicAPI/net461/PublicAPI.Unshipped.txt
@@ -1 +1,2 @@
-#nullable enable
\ No newline at end of file
+#nullable enable
+static Dapper.CommandDefinition.SetCommandSetup(System.Action? setup) -> void
\ No newline at end of file
diff --git a/Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt
index 91b0e1a43..5a14caf54 100644
--- a/Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt
+++ b/Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt
@@ -1 +1,2 @@
-#nullable enable
\ No newline at end of file
+#nullable enable
+static Dapper.CommandDefinition.SetCommandSetup(System.Action? setup) -> void
\ No newline at end of file
diff --git a/Dapper/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/Dapper/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
index 91b0e1a43..5a14caf54 100644
--- a/Dapper/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
+++ b/Dapper/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
@@ -1 +1,2 @@
-#nullable enable
\ No newline at end of file
+#nullable enable
+static Dapper.CommandDefinition.SetCommandSetup(System.Action? setup) -> void
\ No newline at end of file