Skip to content

Commit

Permalink
Merge pull request #4 from petar-m/guid-for-service-key
Browse files Browse the repository at this point in the history
Use Guid instead of string for service key
  • Loading branch information
petar-m authored Jan 1, 2024
2 parents ad14998 + d97bb9b commit 68c5450
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal EventHandlerRegistryBuilder(IServiceCollection services)
/// <returns>A reference to this instance after the operation has completed.</returns>
public EventHandlerRegistryBuilder AddKeyedScoped<TEvent, THandler>() where THandler : class, IEventHandler<TEvent>
{
var eventHandlerKey = Guid.NewGuid().ToString();
var eventHandlerKey = Guid.NewGuid();
_services.AddKeyedScoped<IEventHandler<TEvent>, THandler>(eventHandlerKey);

CreateEventHandlerDescriptor<TEvent, THandler>(eventHandlerKey);
Expand All @@ -44,7 +44,7 @@ public EventHandlerRegistryBuilder AddKeyedScoped<TEvent, THandler>() where THan
/// <returns>A reference to this instance after the operation has completed.</returns>
public EventHandlerRegistryBuilder AddKeyedSingleton<TEvent, THandler>() where THandler : class, IEventHandler<TEvent>
{
var eventHandlerKey = Guid.NewGuid().ToString();
var eventHandlerKey = Guid.NewGuid();
_services.AddKeyedSingleton<IEventHandler<TEvent>, THandler>(eventHandlerKey);

CreateEventHandlerDescriptor<TEvent, THandler>(eventHandlerKey);
Expand All @@ -60,14 +60,14 @@ public EventHandlerRegistryBuilder AddKeyedSingleton<TEvent, THandler>() where T
/// <returns>A reference to this instance after the operation has completed.</returns>
public EventHandlerRegistryBuilder AddKeyedTransient<TEvent, THandler>() where THandler : class, IEventHandler<TEvent>
{
var eventHandlerKey = Guid.NewGuid().ToString();
var eventHandlerKey = Guid.NewGuid();
_services.AddKeyedTransient<IEventHandler<TEvent>, THandler>(eventHandlerKey);

CreateEventHandlerDescriptor<TEvent, THandler>(eventHandlerKey);
return this;
}

internal void CreateEventHandlerDescriptor<TEvent, THandler>(string eventHandlerKey) where THandler : class, IEventHandler<TEvent>
internal void CreateEventHandlerDescriptor<TEvent, THandler>(Guid eventHandlerKey) where THandler : class, IEventHandler<TEvent>
{
var descriptor = new EventHandlerDescriptor(
Key: eventHandlerKey,
Expand Down
2 changes: 1 addition & 1 deletion src/M.EventBrokerSlim/Internal/EventHandlerDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace M.EventBrokerSlim.Internal;

internal sealed record EventHandlerDescriptor(
string Key,
Guid Key,
Type EventType,
Type InterfaceType,
Func<object, object, Task> Handle,
Expand Down

0 comments on commit 68c5450

Please sign in to comment.