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

The CommandProcessor should be thread-safe #42

Merged
merged 1 commit into from
May 17, 2024
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
7 changes: 4 additions & 3 deletions src/Qowaiv.DomainModel/Commands/CommandProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq.Expressions;
using System.Collections.Concurrent;
using System.Linq.Expressions;
using System.Reflection;

namespace Qowaiv.DomainModel.Commands;
Expand All @@ -16,7 +17,7 @@ namespace Qowaiv.DomainModel.Commands;
public abstract class CommandProcessor<TReturnType>
{
/// <summary>Gets the command types sent at least once by the command processor.</summary>
public IReadOnlyCollection<object> CommandTypes => handlers.Keys;
public IReadOnlyCollection<object> CommandTypes => [..handlers.Keys];

Corniel marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>The generic type definition of the command handlers to support.</summary>
/// <remarks>
Expand Down Expand Up @@ -142,5 +143,5 @@ private static Expression<Func<object, object, CancellationToken, TReturnType>>
return Expression.Lambda<Func<object, object, CancellationToken, TReturnType>>(body, handler, cmd, token);
}

private readonly Dictionary<Type, Func<object, object, CancellationToken, TReturnType>> handlers = new();
private readonly ConcurrentDictionary<Type, Func<object, object, CancellationToken, TReturnType>> handlers = new();
}
4 changes: 3 additions & 1 deletion src/Qowaiv.DomainModel/Qowaiv.DomainModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<PackageReleaseNotes>
v1.1.1
- CommandProcessor made thread-safe. #42
v1.1.0
- Expose supported event types via Aggregate.SupportedEventTypes(). #41
- Publish .NET 8.0.
Expand Down
Loading