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

Configured static analysis and applied ConfigureAwait(false) to Core classes #188

Merged
merged 1 commit into from
Dec 1, 2022
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
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,41 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true


###############################
# Reliability Inspections #
###############################

# CA2012: Use ValueTasks correctly
dotnet_diagnostic.CA2012.severity = error

# VSTHRD002 Avoid problematic synchronous waits
dotnet_diagnostic.VSTHRD002.severity = warning

# VSTHRD011 Use AsyncLazy<T>
dotnet_diagnostic.VSTHRD011.severity = warning

# VSTHRD100 Avoid async void methods
dotnet_diagnostic.VSTHRD100.severity = error

# VSTHRD101 Avoid unsupported async delegates
dotnet_diagnostic.VSTHRD101.severity = error

# VSTHRD102 Implement internal logic asynchronously
dotnet_diagnostic.VSTHRD102.severity = error

# VSTHRD103 Call async methods when in an async method
dotnet_diagnostic.VSTHRD103.severity = error

# VSTHRD110 Observe result of async calls
dotnet_diagnostic.VSTHRD110.severity = warning

# VSTHRD111 Use .ConfigureAwait(bool)
dotnet_diagnostic.VSTHRD111.severity = error

# VSTHRD112 Implement System.IAsyncDisposable
dotnet_diagnostic.VSTHRD112.severity = error

# VSTHRD200 Use Async suffix for async methods
dotnet_diagnostic.VSTHRD200.severity = none
12 changes: 12 additions & 0 deletions Core.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<AnalysisModeReliability>true</AnalysisModeReliability>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.27" PrivateAssets="All"/>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" PrivateAssets="All" Condition=" '$(TargetFrawework)' == 'netstandard2.0' "/>
</ItemGroup>
</Project>
13 changes: 7 additions & 6 deletions Core.ElasticSearch/Core.ElasticSearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@


<ItemGroup>
<PackageReference Include="NEST" Version="7.17.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NEST" Version="7.17.5"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Core\Core.csproj"/>
</ItemGroup>

<Import Project="../Core.Build.props"/>
</Project>
4 changes: 2 additions & 2 deletions Core.ElasticSearch/Projections/ElasticSearchProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Handle(EventEnvelope<TEvent> eventEnvelope, CancellationToken
var id = getId(eventEnvelope.Data);
var indexName = IndexNameMapper.ToIndexName<TView>();

var entity = (await elasticClient.GetAsync<TView>(id, i => i.Index(indexName), ct))?.Source ??
var entity = (await elasticClient.GetAsync<TView>(id, i => i.Index(indexName), ct).ConfigureAwait(false))?.Source ??
(TView) Activator.CreateInstance(typeof(TView), true)!;

entity.When(eventEnvelope);
Expand All @@ -37,7 +37,7 @@ await elasticClient.IndexAsync(
entity,
i => i.Index(indexName).Id(id).VersionType(VersionType.External).Version((long)eventEnvelope.Metadata.StreamPosition),
ct
);
).ConfigureAwait(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core.ElasticSearch/Repository/ElasticSearchRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ IElasticClient elasticClient

public async Task<T?> Find(Guid id, CancellationToken cancellationToken)
{
var response = await elasticClient.GetAsync<T>(id, ct: cancellationToken);
var response = await elasticClient.GetAsync<T>(id, ct: cancellationToken).ConfigureAwait(false);
return response?.Source;
}

Expand Down
15 changes: 8 additions & 7 deletions Core.EventStoreDB/Core.EventStoreDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@


<ItemGroup>
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="22.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="22.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Core\Core.csproj"/>
</ItemGroup>

<Import Project="../Core.Build.props"/>
</Project>
2 changes: 1 addition & 1 deletion Core.EventStoreDB/Events/AggregateStreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class AggregateStreamExtensions
cancellationToken: cancellationToken
);

if (await readResult.ReadState == ReadState.StreamNotFound)
if (await readResult.ReadState.ConfigureAwait(false) == ReadState.StreamNotFound)
return null;

var aggregate = (T)Activator.CreateInstance(typeof(T), true)!;
Expand Down
6 changes: 3 additions & 3 deletions Core.EventStoreDB/Repository/EventStoreDBRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Task<ulong> Add(T aggregate, CancellationToken token = default) =>
StreamState.NoStream,
GetEventsToStore(aggregate, TelemetryPropagator.GetPropagationContext(activity)),
cancellationToken: ct
);
).ConfigureAwait(false);
return result.NextExpectedStreamRevision.ToUInt64();
},
token
Expand All @@ -63,7 +63,7 @@ public Task<ulong> Update(T aggregate, ulong? expectedRevision = null, Cancellat
nextVersion,
eventsToAppend,
cancellationToken: ct
);
).ConfigureAwait(false);
return result.NextExpectedStreamRevision.ToUInt64();
},
token
Expand All @@ -81,7 +81,7 @@ public Task<ulong> Delete(T aggregate, ulong? expectedRevision = null, Cancellat
nextVersion,
eventsToAppend,
cancellationToken: ct
);
).ConfigureAwait(false);
return result.NextExpectedStreamRevision.ToUInt64();
},
token
Expand Down
6 changes: 3 additions & 3 deletions Core.EventStoreDB/Repository/RepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static async Task<T> Get<T>(
CancellationToken ct
) where T : class, IAggregate
{
var entity = await repository.Find(id, ct);
var entity = await repository.Find(id, ct).ConfigureAwait(false);

return entity ?? throw AggregateNotFoundException.For<T>(id);
}
Expand All @@ -24,10 +24,10 @@ public static async Task<ulong> GetAndUpdate<T>(
CancellationToken ct = default
) where T : class, IAggregate
{
var entity = await repository.Get(id, ct);
var entity = await repository.Get(id, ct).ConfigureAwait(false);

action(entity);

return await repository.Update(entity, expectedVersion, ct);
return await repository.Update(entity, expectedVersion, ct).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public EventStoreDBSubscriptionCheckpointRepository(
var result = eventStoreClient.ReadStreamAsync(Direction.Backwards, streamName, StreamPosition.End, 1,
cancellationToken: ct);

if (await result.ReadState == ReadState.StreamNotFound)
if (await result.ReadState.ConfigureAwait(false) == ReadState.StreamNotFound)
{
return null;
}

ResolvedEvent? @event = await result.FirstOrDefaultAsync(ct);
ResolvedEvent? @event = await result.FirstOrDefaultAsync(ct).ConfigureAwait(false);

return @event?.Deserialize<CheckpointStored>()?.Position;
}
Expand All @@ -46,7 +46,7 @@ await eventStoreClient.AppendToStreamAsync(
StreamState.StreamExists,
eventToAppend,
cancellationToken: ct
);
).ConfigureAwait(false);
}
catch (WrongExpectedVersionException)
{
Expand All @@ -58,15 +58,15 @@ await eventStoreClient.SetStreamMetadataAsync(
StreamState.NoStream,
new StreamMetadata(1),
cancellationToken: ct
);
).ConfigureAwait(false);

// append event again expecting stream to not exist
await eventStoreClient.AppendToStreamAsync(
streamName,
StreamState.NoStream,
eventToAppend,
cancellationToken: ct
);
).ConfigureAwait(false);
}
}

Expand Down
13 changes: 8 additions & 5 deletions Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionToAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task SubscribeToAll(EventStoreDBSubscriptionToAllOptions subscripti

logger.LogInformation("Subscription to all '{SubscriptionId}'", subscriptionOptions.SubscriptionId);

var checkpoint = await checkpointRepository.Load(SubscriptionId, ct);
var checkpoint = await checkpointRepository.Load(SubscriptionId, ct).ConfigureAwait(false);

await eventStoreClient.SubscribeToAllAsync(
checkpoint == null ? FromAll.Start : FromAll.After(new Position(checkpoint.Value, checkpoint.Value)),
Expand All @@ -70,7 +70,7 @@ await eventStoreClient.SubscribeToAllAsync(
subscriptionOptions.FilterOptions,
subscriptionOptions.Credentials,
ct
);
).ConfigureAwait(false);

logger.LogInformation("Subscription to all '{SubscriptionId}' started", SubscriptionId);
}
Expand Down Expand Up @@ -108,9 +108,10 @@ await activityScope.Run($"{nameof(EventStoreDBSubscriptionToAll)}/{nameof(Handle
async (_, ct) =>
{
// publish event to internal event bus
await eventBus.Publish(eventEnvelope, ct);
await eventBus.Publish(eventEnvelope, ct).ConfigureAwait(false);

await checkpointRepository.Store(SubscriptionId, resolvedEvent.Event.Position.CommitPosition, ct);
await checkpointRepository.Store(SubscriptionId, resolvedEvent.Event.Position.CommitPosition, ct)
.ConfigureAwait(false);
},
new StartActivityOptions
{
Expand All @@ -119,7 +120,7 @@ await activityScope.Run($"{nameof(EventStoreDBSubscriptionToAll)}/{nameof(Handle
Kind = ActivityKind.Consumer
},
token
);
).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down Expand Up @@ -162,7 +163,9 @@ private void Resubscribe()
// As this is a background process then we don't need to have async context here.
using (NoSynchronizationContextScope.Enter())
{
#pragma warning disable VSTHRD002
SubscribeToAll(subscriptionOptions, cancellationToken).Wait(cancellationToken);
#pragma warning restore VSTHRD002
}

resubscribed = true;
Expand Down
6 changes: 3 additions & 3 deletions Core.Kafka/Consumers/KafkaConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
while (!cancellationToken.IsCancellationRequested)
{
// consume event from Kafka
await ConsumeNextEvent(consumer, cancellationToken);
await ConsumeNextEvent(consumer, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e)
Expand Down Expand Up @@ -96,7 +96,7 @@ await activityScope.Run($"{nameof(KafkaConsumer)}/{nameof(ConsumeNextEvent)}",
async (_, ct) =>
{
// publish event to internal event bus
await eventBus.Publish(eventEnvelope, ct);
await eventBus.Publish(eventEnvelope, ct).ConfigureAwait(false);

consumer.Commit();
},
Expand All @@ -118,7 +118,7 @@ await activityScope.Run($"{nameof(KafkaConsumer)}/{nameof(ConsumeNextEvent)}",
Kind = ActivityKind.Consumer
},
token
);
).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
11 changes: 6 additions & 5 deletions Core.Kafka/Core.Kafka.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="1.9.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Confluent.Kafka" Version="1.9.3"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Core\Core.csproj"/>
</ItemGroup>

<Import Project="../Core.Build.props"/>
</Project>
2 changes: 1 addition & 1 deletion Core.Kafka/Producers/KafkaProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ await p.ProduceAsync(config.Topic,
Kind = ActivityKind.Producer
},
token
);
).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
15 changes: 8 additions & 7 deletions Core.Marten/Core.Marten.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Marten" Version="6.0.0-alpha.3" />
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Marten" Version="6.0.0-alpha.3"/>
<PackageReference Include="MediatR" Version="11.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core.Serialization\Core.Serialization.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Core.Serialization\Core.Serialization.csproj"/>
<ProjectReference Include="..\Core\Core.csproj"/>
</ItemGroup>

<Import Project="../Core.Build.props"/>
</Project>
4 changes: 2 additions & 2 deletions Core.Marten/ExternalProjections/MartenExternalProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Handle(EventEnvelope<TEvent> eventEnvelope, CancellationToken
{
var (@event, eventMetadata) = eventEnvelope;

var entity = await session.LoadAsync<TView>(getId(@event), ct) ??
var entity = await session.LoadAsync<TView>(getId(@event), ct).ConfigureAwait(false) ??
(TView)Activator.CreateInstance(typeof(TView), true)!;

var eventLogPosition = eventMetadata.LogPosition;
Expand All @@ -39,7 +39,7 @@ public async Task Handle(EventEnvelope<TEvent> eventEnvelope, CancellationToken

session.Store(entity);

await session.SaveChangesAsync(ct);
await session.SaveChangesAsync(ct).ConfigureAwait(false);
}
}

Expand Down
Loading