/// <inheritdoc /> public virtual void Handle(IMessageContext messageContext) { var hasHandlersGenericMethod = typeof(IDomainEventsManager).GetTypeInfo().GetMethod("HasHandlers") .MakeGenericMethod(messageContext.Content.GetType()); if ((bool)hasHandlersGenericMethod.Invoke(eventsManager, new object[] { })) { var raiseGenericMethod = eventsManager.GetType().GetTypeInfo().GetMethod("Raise") .MakeGenericMethod(messageContext.Content.GetType()); messageContext.Items.TryGetValue(EventHandlerLocatorMiddleware.HandlerMethodsKey, out object handlersObj); var handlers = handlersObj as EventHandlerMethodWithObject[]; messageContext.Items[EventHandlerLocatorMiddleware.HandlerMethodsKey] = ArrayHelpers.AddItem(handlers, new EventHandlerMethodWithObject(raiseGenericMethod, eventsManager)); } }