Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Dapper/CommandDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ internal static CommandDefinition ForCallback(object? parameters, CommandFlags f
return new CommandDefinition(parameters is DynamicParameters ? parameters : null, flags);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="setup">The callback to invoke after command setup, or null to clear.</param>
public static void SetCommandSetup(Action<IDbCommand>? setup)
{
commandSetup = setup;
}

internal void OnCompleted()
{
(Parameters as SqlMapper.IParameterCallbacks)?.OnCompleted();
Expand Down Expand Up @@ -136,11 +147,14 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object?>?
}
cmd.CommandType = CommandTypeDirect;
paramReader?.Invoke(cmd, Parameters);
commandSetup?.Invoke(cmd);
return cmd;
}

private static SqlMapper.Link<Type, Action<IDbCommand>>? commandInitCache;

private static Action<IDbCommand>? commandSetup;

internal static void ResetCommandInitCache()
=> SqlMapper.Link<Type, Action<IDbCommand>>.Clear(ref commandInitCache);

Expand Down
3 changes: 2 additions & 1 deletion Dapper/PublicAPI/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
#nullable enable
static Dapper.CommandDefinition.SetCommandSetup(System.Action<System.Data.IDbCommand>? setup) -> void
3 changes: 2 additions & 1 deletion Dapper/PublicAPI/net8.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
#nullable enable
static Dapper.CommandDefinition.SetCommandSetup(System.Action<System.Data.IDbCommand>? setup) -> void
3 changes: 2 additions & 1 deletion Dapper/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
#nullable enable
static Dapper.CommandDefinition.SetCommandSetup(System.Action<System.Data.IDbCommand>? setup) -> void