Skip to content

Commit

Permalink
Use a ConcurrentDictionary to be thread-safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed May 17, 2024
1 parent 450434d commit 4d476dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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];

/// <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

0 comments on commit 4d476dc

Please sign in to comment.