handler fix

This commit is contained in:
TheXamlGuy
2024-01-07 22:38:50 +00:00
parent 9a669e695e
commit e72d997563
+4 -6
View File
@@ -8,7 +8,7 @@ public class Mediator(IServiceProvider provider) :
{ {
private readonly ConditionalWeakTable<Type, dynamic> addedHandlers = []; private readonly ConditionalWeakTable<Type, dynamic> addedHandlers = [];
public async ValueTask PublishAsync<TNotification>(TNotification notification, public ValueTask PublishAsync<TNotification>(TNotification notification,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
where TNotification : where TNotification :
INotification INotification
@@ -24,14 +24,12 @@ public class Mediator(IServiceProvider provider) :
} }
} }
if (handlers.Count == 0) foreach (INotificationHandler<TNotification> handler in handlers)
{ {
} return handler.Handle(notification, cancellationToken);
else if (handlers.Count == 1)
{
await handlers[0].Handle(notification, cancellationToken);
} }
return default;
} }
public ValueTask<TResponse> SendAsync<TResponse>(IRequest<TResponse> request, public ValueTask<TResponse> SendAsync<TResponse>(IRequest<TResponse> request,