Refactor envelope creation logic and add IEnvelopeExecutor
Updated CreateEnvelopeCommandHandler to use IEnvelopeExecutor for managing envelope creation. Introduced CreateParmas method for parameter handling in CreateEnvelopeSQL. Corrected Dapper type mapping method name and added service registration for IEnvelopeExecutor in DependencyExtensions. Refactored SQLExecutor to enhance encapsulation. Created EnvelopeExecutor class implementing IEnvelopeExecutor for dedicated envelope operations.
This commit is contained in:
@@ -8,26 +8,26 @@ namespace EnvelopeGenerator.Infrastructure.Executor;
|
||||
|
||||
public class SQLExecutor : ISQLExecutor
|
||||
{
|
||||
private readonly SQLExecutorParams _params;
|
||||
protected readonly SQLExecutorParams Params;
|
||||
|
||||
private readonly IServiceProvider _provider;
|
||||
protected readonly IServiceProvider Provider;
|
||||
|
||||
public SQLExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions)
|
||||
{
|
||||
_provider = provider;
|
||||
_params = sqlExecutorParamsOptions.Value;
|
||||
Provider = provider;
|
||||
Params = sqlExecutorParamsOptions.Value;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TEntity>> Execute<TEntity>(string sql, DynamicParameters parameters, CancellationToken cancellation = default)
|
||||
{
|
||||
using var connection = new SqlConnection(_params.ConnectionString);
|
||||
using var connection = new SqlConnection(Params.ConnectionString);
|
||||
await connection.OpenAsync(cancellation);
|
||||
return await connection.QueryAsync<TEntity>(sql, parameters);
|
||||
}
|
||||
|
||||
public Task<IEnumerable<TEntity>> Execute<TEntity, TSQL>(DynamicParameters parameters, CancellationToken cancellation = default) where TSQL : ISQL
|
||||
{
|
||||
var sql = _provider.GetRequiredService<TSQL>();
|
||||
var sql = Provider.GetRequiredService<TSQL>();
|
||||
return Execute<TEntity>(sql.Raw, parameters, cancellation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user