From 0ef71d75c3763e96ec6ccd19beb0bb3a431a448c Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 10 Jan 2022 17:03:59 +0800 Subject: [PATCH] Add `notAnEventHandler`. --- .../Volo/Abp/EventBus/EventHandlerInvoker.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs index 6269500687..a75b1bb3fa 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs @@ -17,11 +17,13 @@ public class EventHandlerInvoker : IEventHandlerInvoker, ISingletonDependency public async Task InvokeAsync(IEventHandler eventHandler, object eventData, Type eventType) { + var notAnEventHandler = true; if (typeof(ILocalEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler)) { var eventHandlerCall = _cache.GetOrAdd($"{typeof(LocalEventHandlerMethodExecutor<>).FullName}{eventHandler.GetType().FullName}-{eventType.FullName}", (_) => (IEventHandlerMethodExecutor)Activator.CreateInstance(typeof(LocalEventHandlerMethodExecutor<>).MakeGenericType(eventType))); await eventHandlerCall.ExecutorAsync(eventHandler, eventData); + notAnEventHandler = false; } if (typeof(IDistributedEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler)) @@ -29,10 +31,10 @@ public class EventHandlerInvoker : IEventHandlerInvoker, ISingletonDependency var eventHandlerCall = _cache.GetOrAdd($"{typeof(DistributedEventHandlerMethodExecutor<>).FullName}{eventHandler.GetType().FullName}-{eventType.FullName}", (_) => (IEventHandlerMethodExecutor)Activator.CreateInstance(typeof(DistributedEventHandlerMethodExecutor<>).MakeGenericType(eventType))); await eventHandlerCall.ExecutorAsync(eventHandler, eventData); + notAnEventHandler = false; } - if (!typeof(ILocalEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler) && - !typeof(IDistributedEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler)) + if (notAnEventHandler) { throw new AbpException("The object instance is not an event handler. Object type: " + eventHandler.GetType().AssemblyQualifiedName); }