Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and chain ConfigureAwait(false) on all awaits to allow blocking on async methods without deadlocking #456

Merged
merged 2 commits into from
Mar 7, 2025
Merged
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
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ dotnet_naming_rule.private_fields_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

## Code Quality Analysis
dotnet_diagnostic.CA2007.severity = error # Use ConfigureAwait
configure_await_analysis_mode = library
2 changes: 1 addition & 1 deletion src/DapperRepository.BulkInsert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public virtual async Task<int> BulkInsertAsync(IEnumerable<TEntity> instances, I
var items = instances.Skip(i * maxAllowedInstancesPerBatch).Take(maxAllowedInstancesPerBatch);
var msSqlQueryResult = SqlGenerator.GetBulkInsert(items);
count += await Connection.ExecuteAsync(new CommandDefinition(msSqlQueryResult.GetSql(), msSqlQueryResult.Param, transaction,
cancellationToken: cancellationToken));
cancellationToken: cancellationToken)).ConfigureAwait(false);
}

return count;
Expand Down
4 changes: 2 additions & 2 deletions src/DapperRepository.BulkUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public virtual async Task<bool> BulkUpdateAsync(IEnumerable<TEntity> instances,
var items = instances.Skip(skips).Take(maxAllowedInstancesPerBatch);
var msSqlQueryResult = SqlGenerator.GetBulkUpdate(items);
count += await Connection.ExecuteAsync(new CommandDefinition(msSqlQueryResult.GetSql(), msSqlQueryResult.Param, transaction,
cancellationToken: cancellationToken));
cancellationToken: cancellationToken)).ConfigureAwait(false);
}

return count > 0;
}
}

var queryResult = SqlGenerator.GetBulkUpdate(instances);
var result = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken)) > 0;
var result = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
return result;
}
}
4 changes: 2 additions & 2 deletions src/DapperRepository.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public virtual async Task<bool> DeleteAsync(TEntity instance, IDbTransaction? tr
if (timeout.HasValue)
commandTimeout = timeout.Value.Seconds;
var deleted = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout,
cancellationToken: cancellationToken)) > 0;
cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
return deleted;
}

Expand All @@ -106,7 +106,7 @@ public virtual async Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? pre
if (timeout.HasValue)
commandTimeout = timeout.Value.Seconds;
var deleted = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout,
cancellationToken: cancellationToken)) > 0;
cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
return deleted;
}
}
12 changes: 6 additions & 6 deletions src/DapperRepository.ExecuteJoinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,31 @@
await Connection.QueryAsync<TEntity, TChild1, TEntity>(new CommandDefinition(sqlQuery.GetSql(),
sqlQuery.Param, transaction, flags: buffered, cancellationToken: cancellationToken), (entity, child1) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1),
spiltOn);
spiltOn).ConfigureAwait(false);
break;

case 2:
await Connection.QueryAsync<TEntity, TChild1, TChild2, TEntity>(new CommandDefinition(sqlQuery.GetSql(),
sqlQuery.Param, transaction, flags: buffered, cancellationToken: cancellationToken), (entity, child1, child2) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1,
child2),
spiltOn);
spiltOn).ConfigureAwait(false);
break;

case 3:
await Connection.QueryAsync<TEntity, TChild1, TChild2, TChild3, TEntity>(new CommandDefinition(sqlQuery.GetSql(),
sqlQuery.Param, transaction, flags: buffered, cancellationToken: cancellationToken), (entity, child1, child2, child3) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1,
child2, child3),
spiltOn);
spiltOn).ConfigureAwait(false);
break;

case 4:
await Connection.QueryAsync<TEntity, TChild1, TChild2, TChild3, TChild4, TEntity>(new CommandDefinition(sqlQuery.GetSql(),
sqlQuery.Param, transaction, flags: buffered, cancellationToken: cancellationToken), (entity, child1, child2, child3, child4) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1,
child2, child3, child4),
spiltOn);
spiltOn).ConfigureAwait(false);

Check warning on line 194 in src/DapperRepository.ExecuteJoinQuery.cs

View check run for this annotation

Codecov / codecov/patch

src/DapperRepository.ExecuteJoinQuery.cs#L194

Added line #L194 was not covered by tests
break;

case 5:
Expand All @@ -200,7 +200,7 @@
(entity, child1, child2, child3, child4, child5) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1,
child2, child3, child4, child5),
spiltOn);
spiltOn).ConfigureAwait(false);

Check warning on line 203 in src/DapperRepository.ExecuteJoinQuery.cs

View check run for this annotation

Codecov / codecov/patch

src/DapperRepository.ExecuteJoinQuery.cs#L203

Added line #L203 was not covered by tests
break;

case 6:
Expand All @@ -209,7 +209,7 @@
(entity, child1, child2, child3, child4, child5, child6) =>
EntityJoinMapping<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(lookup, keyProperties, childKeyProperties, childProperties, entity, child1,
child2, child3, child4, child5, child6),
spiltOn);
spiltOn).ConfigureAwait(false);

Check warning on line 212 in src/DapperRepository.ExecuteJoinQuery.cs

View check run for this annotation

Codecov / codecov/patch

src/DapperRepository.ExecuteJoinQuery.cs#L212

Added line #L212 was not covered by tests
break;

default:
Expand Down
6 changes: 3 additions & 3 deletions src/DapperRepository.Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ public virtual async Task<bool> InsertAsync(TEntity instance, IDbTransaction? tr
{
if (SqlGenerator.Provider == Repositories.SqlGenerator.SqlProvider.Oracle)
{
await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken));
await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false);
int newId = ((DynamicParameters)(queryResult.Param!)).Get<int>(":newId");
return SetValue(newId, instance);
}
else
{
var newId = (await Connection.QueryAsync<long>(queryResult.GetSql(), queryResult.Param, transaction)).FirstOrDefault();
var newId = (await Connection.QueryAsync<long>(queryResult.GetSql(), queryResult.Param, transaction).ConfigureAwait(false)).FirstOrDefault();
return SetValue(newId, instance);
}
}

return await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), instance, transaction, cancellationToken: cancellationToken)) > 0;
return await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), instance, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
}

private bool SetValue(long newId, TEntity instance)
Expand Down
4 changes: 2 additions & 2 deletions src/DapperRepository.Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public virtual async Task<bool> UpdateAsync(TEntity instance, IDbTransaction? tr
params Expression<Func<TEntity, object>>[] includes)
{
var sqlQuery = SqlGenerator.GetUpdate(instance, includes);
var updated = await Connection.ExecuteAsync(new CommandDefinition(sqlQuery.GetSql(), sqlQuery.Param, transaction, cancellationToken: cancellationToken)) > 0;
var updated = await Connection.ExecuteAsync(new CommandDefinition(sqlQuery.GetSql(), sqlQuery.Param, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
return updated;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public virtual async Task<bool> UpdateAsync(Expression<Func<TEntity, bool>>? pre
params Expression<Func<TEntity, object>>[] includes)
{
var sqlQuery = SqlGenerator.GetUpdate(predicate, instance, includes);
var updated = await Connection.ExecuteAsync(new CommandDefinition(sqlQuery.GetSql(), sqlQuery.Param, transaction, cancellationToken: cancellationToken)) > 0;
var updated = await Connection.ExecuteAsync(new CommandDefinition(sqlQuery.GetSql(), sqlQuery.Param, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false) > 0;
return updated;
}
}
1 change: 1 addition & 0 deletions src/MicroOrm.Dapper.Repositories.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageOutputPath>nupkgs</PackageOutputPath>
<IsPackable>true</IsPackable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="SqlGenerator.Tests" />
Expand Down
12 changes: 6 additions & 6 deletions src/ReadOnlyDapperRepository.Find.Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1);
return (await ExecuteJoinQueryAsync<TChild1, DontMap, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, DontMap, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1).ConfigureAwait(false)).FirstOrDefault();
}


Expand Down Expand Up @@ -205,7 +205,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1, tChild2);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, TChild2, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2).ConfigureAwait(false)).FirstOrDefault();

Check warning on line 208 in src/ReadOnlyDapperRepository.Find.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.Find.Join.cs#L208

Added line #L208 was not covered by tests
}


Expand Down Expand Up @@ -246,7 +246,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1, tChild2, tChild3);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3).ConfigureAwait(false)).FirstOrDefault();

Check warning on line 249 in src/ReadOnlyDapperRepository.Find.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.Find.Join.cs#L249

Added line #L249 was not covered by tests
}


Expand Down Expand Up @@ -291,7 +291,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1, tChild2, tChild3, tChild4);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4))
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4).ConfigureAwait(false))

Check warning on line 294 in src/ReadOnlyDapperRepository.Find.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.Find.Join.cs#L294

Added line #L294 was not covered by tests
.FirstOrDefault();
}

Expand Down Expand Up @@ -341,7 +341,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1, tChild2, tChild3, tChild4, tChild5);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5))
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5).ConfigureAwait(false))

Check warning on line 344 in src/ReadOnlyDapperRepository.Find.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.Find.Join.cs#L344

Added line #L344 was not covered by tests
.FirstOrDefault();
}

Expand Down Expand Up @@ -396,6 +396,6 @@
{
var queryResult = SqlGenerator.GetSelectFirst(predicate, FilterData, tChild1, tChild2, tChild3, tChild4, tChild5, tChild6);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5,
tChild6)).FirstOrDefault();
tChild6).ConfigureAwait(false)).FirstOrDefault();

Check warning on line 399 in src/ReadOnlyDapperRepository.Find.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.Find.Join.cs#L399

Added line #L399 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion src/ReadOnlyDapperRepository.FindAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public virtual Task<IEnumerable<TEntity>> FindAllAsync(Expression<Func<TEntity,
public virtual async Task<IEnumerable<TEntity>> FindAllAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectAll(predicate, FilterData);
return await Connection.QueryAsync<TEntity>(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken));
return await Connection.QueryAsync<TEntity>(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, cancellationToken: cancellationToken)).ConfigureAwait(false);
}
}
12 changes: 6 additions & 6 deletions src/ReadOnlyDapperRepository.FindById.Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1);
return (await ExecuteJoinQueryAsync<TChild1, DontMap, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, DontMap, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1).ConfigureAwait(false)).FirstOrDefault();
}


Expand Down Expand Up @@ -209,7 +209,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1, tChild2);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, TChild2, DontMap, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2).ConfigureAwait(false)).FirstOrDefault();

Check warning on line 212 in src/ReadOnlyDapperRepository.FindById.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.FindById.Join.cs#L212

Added line #L212 was not covered by tests
}


Expand Down Expand Up @@ -250,7 +250,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1, tChild2, tChild3);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3)).FirstOrDefault();
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, DontMap, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3).ConfigureAwait(false)).FirstOrDefault();
}


Expand Down Expand Up @@ -295,7 +295,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1, tChild2, tChild3, tChild4);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4))
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, DontMap, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4).ConfigureAwait(false))

Check warning on line 298 in src/ReadOnlyDapperRepository.FindById.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.FindById.Join.cs#L298

Added line #L298 was not covered by tests
.FirstOrDefault();
}

Expand Down Expand Up @@ -345,7 +345,7 @@
CancellationToken cancellationToken)
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1, tChild2, tChild3, tChild4, tChild5);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5))
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, DontMap>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5).ConfigureAwait(false))

Check warning on line 348 in src/ReadOnlyDapperRepository.FindById.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.FindById.Join.cs#L348

Added line #L348 was not covered by tests
.FirstOrDefault();
}

Expand Down Expand Up @@ -400,6 +400,6 @@
{
var queryResult = SqlGenerator.GetSelectById(id, FilterData, tChild1, tChild2, tChild3, tChild4, tChild5, tChild6);
return (await ExecuteJoinQueryAsync<TChild1, TChild2, TChild3, TChild4, TChild5, TChild6>(queryResult, transaction, cancellationToken, tChild1, tChild2, tChild3, tChild4, tChild5,
tChild6)).FirstOrDefault();
tChild6).ConfigureAwait(false)).FirstOrDefault();

Check warning on line 403 in src/ReadOnlyDapperRepository.FindById.Join.cs

View check run for this annotation

Codecov / codecov/patch

src/ReadOnlyDapperRepository.FindById.Join.cs#L403

Added line #L403 was not covered by tests
}
}