Skip to content

Commit

Permalink
Merge pull request #20 from simplesoft-pt/feat/configure-await-false
Browse files Browse the repository at this point in the history
force ConfigureAwait flag to false
  • Loading branch information
gravity00 authored Oct 27, 2021
2 parents ae96c22 + 2f48612 commit 379d53c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public async Task OnCommandAsync<TCommand>(Func<TCommand, CancellationToken, Tas
{
if (!_options.BeginTransactionOnCommand)
{
await next(cmd, ct);
await next(cmd, ct).ConfigureAwait(false);
return;
}

_logger.LogDebug("Starting a command transaction");

await _transaction.BeginAsync(ct);
await _transaction.BeginAsync(ct).ConfigureAwait(false);

await next(cmd, ct);
await next(cmd, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _transaction.CommitAsync(ct);
await _transaction.CommitAsync(ct).ConfigureAwait(false);

_logger.LogInformation("Changes committed into the database");
}
Expand All @@ -59,18 +59,18 @@ public async Task<TResult> OnCommandAsync<TCommand, TResult>(Func<TCommand, Canc
{
if (!_options.BeginTransactionOnCommand)
{
return await next(cmd, ct);
return await next(cmd, ct).ConfigureAwait(false);
}

_logger.LogDebug("Starting a command transaction");

await _transaction.BeginAsync(ct);
await _transaction.BeginAsync(ct).ConfigureAwait(false);

var result = await next(cmd, ct);
var result = await next(cmd, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _transaction.CommitAsync(ct);
await _transaction.CommitAsync(ct).ConfigureAwait(false);

_logger.LogInformation("Changes committed into the database");

Expand All @@ -82,19 +82,19 @@ public async Task OnEventAsync<TEvent>(Func<TEvent, CancellationToken, Task> nex
{
if (!_options.BeginTransactionOnEvent)
{
await next(evt, ct);
await next(evt, ct).ConfigureAwait(false);
return;
}

_logger.LogDebug("Starting an event transaction");

await _transaction.BeginAsync(ct);
await _transaction.BeginAsync(ct).ConfigureAwait(false);

await next(evt, ct);
await next(evt, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _transaction.CommitAsync(ct);
await _transaction.CommitAsync(ct).ConfigureAwait(false);

_logger.LogInformation("Changes committed into the database");
}
Expand All @@ -104,26 +104,26 @@ public async Task<TResult> OnQueryAsync<TQuery, TResult>(Func<TQuery, Cancellati
{
if (!_options.BeginTransactionOnQuery)
{
return await next(query, ct);
return await next(query, ct).ConfigureAwait(false);
}

_logger.LogDebug("Starting a query transaction");

await _transaction.BeginAsync(ct);
await _transaction.BeginAsync(ct).ConfigureAwait(false);

var result = await next(query, ct);
var result = await next(query, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

if (_options.ForceRollbackOnQuery)
{
await _transaction.RollbackAsync(ct);
await _transaction.RollbackAsync(ct).ConfigureAwait(false);

_logger.LogInformation("Changes were reverted from the database");
}
else
{
await _transaction.CommitAsync(ct);
await _transaction.CommitAsync(ct).ConfigureAwait(false);

_logger.LogInformation("Changes committed into the database");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ public async Task OnCommandAsync<TCommand>(Func<TCommand, CancellationToken, Tas
{
if (!_options.BeginTransactionOnCommand)
{
await next(cmd, ct);
await next(cmd, ct).ConfigureAwait(false);
return;
}

_logger.LogDebug("Starting a command transaction");

#if NETSTANDARD2_1
await using var tx = await _context.Database.BeginTransactionAsync(ct);
await using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#else
using var tx = await _context.Database.BeginTransactionAsync(ct);
using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#endif

await next(cmd, ct);
await next(cmd, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _context.SaveChangesAsync(ct);
await _context.SaveChangesAsync(ct).ConfigureAwait(false);

#if NETSTANDARD2_1
await tx.CommitAsync(ct);
await tx.CommitAsync(ct).ConfigureAwait(false);
#else
tx.Commit();
#endif
Expand All @@ -69,25 +69,25 @@ public async Task<TResult> OnCommandAsync<TCommand, TResult>(Func<TCommand, Canc
{
if (!_options.BeginTransactionOnCommand)
{
return await next(cmd, ct);
return await next(cmd, ct).ConfigureAwait(false);
}

_logger.LogDebug("Starting a command transaction");

#if NETSTANDARD2_1
await using var tx = await _context.Database.BeginTransactionAsync(ct);
await using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#else
using var tx = await _context.Database.BeginTransactionAsync(ct);
using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#endif

var result = await next(cmd, ct);
var result = await next(cmd, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _context.SaveChangesAsync(ct);
await _context.SaveChangesAsync(ct).ConfigureAwait(false);

#if NETSTANDARD2_1
await tx.CommitAsync(ct);
await tx.CommitAsync(ct).ConfigureAwait(false);
#else
tx.Commit();
#endif
Expand All @@ -102,26 +102,26 @@ public async Task OnEventAsync<TEvent>(Func<TEvent, CancellationToken, Task> nex
{
if (!_options.BeginTransactionOnEvent)
{
await next(evt, ct);
await next(evt, ct).ConfigureAwait(false);
return;
}

_logger.LogDebug("Starting an event transaction");

#if NETSTANDARD2_1
await using var tx = await _context.Database.BeginTransactionAsync(ct);
await using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#else
using var tx = await _context.Database.BeginTransactionAsync(ct);
using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#endif

await next(evt, ct);
await next(evt, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

await _context.SaveChangesAsync(ct);
await _context.SaveChangesAsync(ct).ConfigureAwait(false);

#if NETSTANDARD2_1
await tx.CommitAsync(ct);
await tx.CommitAsync(ct).ConfigureAwait(false);
#else
tx.Commit();
#endif
Expand All @@ -134,26 +134,26 @@ public async Task<TResult> OnQueryAsync<TQuery, TResult>(Func<TQuery, Cancellati
{
if (!_options.BeginTransactionOnQuery)
{
return await next(query, ct);
return await next(query, ct).ConfigureAwait(false);
}

_logger.LogDebug("Starting a query transaction");

#if NETSTANDARD2_1
await using var tx = await _context.Database.BeginTransactionAsync(ct);
await using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#else
using var tx = await _context.Database.BeginTransactionAsync(ct);
using var tx = await _context.Database.BeginTransactionAsync(ct).ConfigureAwait(false);
#endif

var result = await next(query, ct);
var result = await next(query, ct).ConfigureAwait(false);

_logger.LogDebug("Saving changes into the database");

if (_options.ForceRollbackOnQuery)
{

#if NETSTANDARD2_1
await tx.RollbackAsync(ct);
await tx.RollbackAsync(ct).ConfigureAwait(false);
#else
tx.Rollback();
#endif
Expand All @@ -162,10 +162,10 @@ public async Task<TResult> OnQueryAsync<TQuery, TResult>(Func<TQuery, Cancellati
}
else
{
await _context.SaveChangesAsync(ct);
await _context.SaveChangesAsync(ct).ConfigureAwait(false);

#if NETSTANDARD2_1
await tx.CommitAsync(ct);
await tx.CommitAsync(ct).ConfigureAwait(false);
#else
tx.Commit();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override async Task BroadcastAsync(TEvent evt, CancellationToken ct)
using (_logger.BeginScope("EventName:{eventName} EventId:{eventId}", evt.GetType().Name, evt.Id))
{
_logger.LogDebug("Broadcasting event");
await base.BroadcastAsync(evt, ct);
await base.BroadcastAsync(evt, ct).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override async Task<TResult> FetchAsync(TQuery query, CancellationToken c
using (_logger.BeginScope("QueryName:{queryName} QueryId:{queryId}", query.GetType().Name, query.Id))
{
_logger.LogDebug("Fetching query data");
return await base.FetchAsync(query, ct);
return await base.FetchAsync(query, ct).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override async Task SendAsync(TCommand cmd, CancellationToken ct)
using (_logger.BeginScope("CommandName:{commandName} CommandId:{commandId}", cmd.GetType().Name, cmd.Id))
{
_logger.LogDebug("Sending command");
await base.SendAsync(cmd, ct);
await base.SendAsync(cmd, ct).ConfigureAwait(false);
}
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public override async Task<TResult> SendAsync(TCommand cmd, CancellationToken ct
using (_logger.BeginScope("CommandName:{commandName} CommandId:{commandId}", cmd.GetType().Name, cmd.Id))
{
_logger.LogDebug("Sending command");
return await base.SendAsync(cmd, ct);
return await base.SendAsync(cmd, ct).ConfigureAwait(false);
}
}
}
Expand Down

0 comments on commit 379d53c

Please sign in to comment.