public async Task <T> Query <T>(ISingleQueryHandler <T> handler, CancellationToken cancellation) { using var conn = _database.CreateConnection(); var command = handler.BuildCommand(); command.Connection = conn; await conn.OpenAsync(cancellation).ConfigureAwait(false); using var reader = await command.ExecuteReaderAsync(cancellation).ConfigureAwait(false); try { return(await handler.HandleAsync(reader, cancellation).ConfigureAwait(false)); } finally { #if NET6_0_OR_GREATER await reader.CloseAsync().ConfigureAwait(false); #else #pragma warning disable VSTHRD103 reader.Close(); #pragma warning restore VSTHRD103 #endif await conn.CloseAsync().ConfigureAwait(false); } }
public async Task <T> Query <T>(ISingleQueryHandler <T> handler, CancellationToken cancellation) { using var conn = _tenant.CreateConnection(); var command = handler.BuildCommand(); command.Connection = conn; await conn.OpenAsync(cancellation); using var reader = await command.ExecuteReaderAsync(cancellation); return(await handler.HandleAsync(reader, cancellation)); }
public async Task <T> Query <T>(ISingleQueryHandler <T> handler, CancellationToken cancellation) { try { var command = handler.BuildCommand(); command.Connection = _connection; using var reader = await command.ExecuteReaderAsync(cancellation).ConfigureAwait(false); return(await handler.HandleAsync(reader, cancellation).ConfigureAwait(false)); } catch (Exception) { // Let the caller deal with retries await reopenConnectionIfNecessary(cancellation).ConfigureAwait(false); throw; } }