/// <summary> /// Gets the set of <see cref="EventHandler"/> instances associated with the specified <paramref name="e"/>. /// </summary> /// <param name="e">The event for which to retrieve all <see cref="EventHandler"/> instances.</param> public IEnumerable<EventHandler> GetHandlersFor(Event e) { Verify.NotNull(e, nameof(e)); EventHandler[] eventHandlers; Timeout timeout = e as Timeout; if (timeout != null && knownSagaTimeoutHandlers.TryGetValue(timeout.SagaType, out eventHandlers)) return eventHandlers; return knownEventHandlers.TryGetValue(e.GetType(), out eventHandlers) ? eventHandlers : Enumerable.Empty<EventHandler>(); }
/// <summary> /// Get the associated apply method for the specified <see cref="Event"/> <paramref name="e"/> from the known <paramref name="applyMethods"/>. /// </summary> /// <param name="aggregate">The <see cref="Aggregate"/> instance on which the event is to be applied.</param> /// <param name="e">The <see cref="Event"/> to be applied.</param> /// <param name="applyMethods">The set of known apply methods for a given aggregate instance</param> private static Action<Aggregate, Event> GetApplyMethod(Aggregate aggregate, Event e, ApplyMethodCollection applyMethods) { Action<Aggregate, Event> applyMethod; Type eventType = e.GetType(); if (applyMethods.TryGetValue(eventType, out applyMethod)) return applyMethod; if (!applyMethods.ApplyOptional) throw new MappingException(Exceptions.AggregateApplyMethodNotFound.FormatWith(aggregate.GetType(), e.GetType())); return VoidApplyMethod; }