Allow the Mediator to be subscribed to and therefore handled

This commit is contained in:
TheXamlGuy
2024-05-15 19:28:08 +01:00
parent 7e57c0d28d
commit 8c0436644a
6 changed files with 67 additions and 24 deletions
+5 -7
View File
@@ -25,12 +25,11 @@ public class Publisher(IHandlerProvider handlerProvider,
object? key = null)
{
Type notificationType = message.GetType();
Type handlerType = typeof(NotificationHandlerWrapper<>)
.MakeGenericType(notificationType);
List<object?> handlers = provider.GetServices(typeof(NotificationHandlerWrapper<>)
.MakeGenericType(notificationType)).ToList();
foreach (object? handler in handlerProvider
.Get(notificationType, key!))
List<object?> handlers = provider.GetServices(handlerType).ToList();
foreach (object? handler in handlerProvider.Get(notificationType, key))
{
handlers.Add(handler);
}
@@ -39,8 +38,7 @@ public class Publisher(IHandlerProvider handlerProvider,
{
if (handler is not null)
{
Type? handlerType = handler.GetType();
MethodInfo? handleMethod = handlerType.GetMethod("Handle",
MethodInfo? handleMethod = handler.GetType().GetMethod("Handle",
[notificationType]);
if (handleMethod is not null)