public static Task HandleMeWith(this IDomainEvent domainEvent, IHandleEvents eventHandler) { var handlerType = eventHandler.GetType(); var eventType = domainEvent.GetType(); var handlerMethodsForEventType = from method in handlerType.GetTypeInfo().DeclaredMethods from parameter in method.GetParameters() where method.IsPublic where parameter.ParameterType == eventType select method; var allHandlerMethods = handlerMethodsForEventType.ToList(); if (handlerMethodsForEventType.Any() == false) { throw new ArgumentException($"This Event Type {eventType.Name} has no Handler Method"); } if (handlerMethodsForEventType.Count() > 1) { throw new ArgumentException($"This Event Type {eventType.Name} has to much Handler Methods"); } // Invoke the one and only Handle([Event Type]) Method return((Task)handlerMethodsForEventType .Single() .Invoke(eventHandler, new object?[] { domainEvent })); }
protected Aggregate(TId id) { if (id.IsNullOrEmpty()) { throw new ArgumentOutOfRangeException(nameof(id)); } Id = id; _eventFactory = this as ICreateEvents ?? new DefaultEventFactory(); _eventHandler = this as IHandleEvents ?? new DefaultEventHandler(); }
public void Subscribe <T>(IHandleEvents <T> eventHandler) where T : IEvent { if (!_registry.ContainsKey(typeof(T))) { _registry.Add(typeof(T), new List <Action <IEvent> >()); } var handlers = _registry[typeof(T)]; handlers.Add(@event => eventHandler.HandleEvent((T)@event)); }
public void Subscribe(IHandleEvents eventHandler, Type ofEventIHandle) { if (!_registry.ContainsKey(ofEventIHandle)) { _registry.Add(ofEventIHandle, new List <IHandleEvents>()); } var handlers = _registry[ofEventIHandle]; handlers.Add(eventHandler); }
public static void HandleMeWith(this IAmAnEventMessage @event, IHandleEvents handler) { var handlerType = handler.GetType (); var eventType = @event.GetType (); var eventHandlerMethods = from method in handlerType.GetTypeInfo().DeclaredMethods from parameter in method.GetParameters () where parameter.ParameterType == eventType select method; var allMethodes = eventHandlerMethods.ToList (); if (allMethodes.Any ()) { if (allMethodes.Count () > 1) { throw new MultipleHandlerMethodesDetected (eventType.Name); } allMethodes.First ().Invoke (handler, new object[]{ @event }); } }
public static void HandleMeWith(this IAmAnEventMessage @event, IHandleEvents handler) { var handlerType = handler.GetType(); var eventType = @event.GetType(); var eventHandlerMethods = from method in handlerType.GetTypeInfo().DeclaredMethods from parameter in method.GetParameters() where parameter.ParameterType == eventType select method; var allMethodes = eventHandlerMethods.ToList(); if (allMethodes.Any()) { if (allMethodes.Count() > 1) { throw new MultipleHandlerMethodesDetected(eventType.Name); } allMethodes.First().Invoke(handler, new object[] { @event }); } }
public ReceiveMessage(IHandleEvents salesEventHandler) { _salesEventHandler = salesEventHandler; }
public IConcatenateEventHandler And(IHandleEvents eventHandler) { _receiver.Add (eventHandler); return this; }
/// <summary> /// Register or reregister an event handler. /// </summary> public void Subscribe(IHandleEvents eventHandler, ISelectEvents eventFilter = null) { eventFilter = eventFilter ?? DelegateSelector.Any; _eventHandlers[eventHandler] = eventFilter; }
public IConcatenateEventHandler PublishNewStateTo(IHandleEvents eventHandler) { _eventHandlers.Add(eventHandler); return(_eventHandlers); }
public void Unregister(IHandleEvents handler) { }
public void To(IHandleEvents eventHandler) { eventHandler.Receive(_currentAggregateEvents); }
public void Unregister(IHandleEvents handler) { lock (_subscribers) _subscribers.Remove(handler); }
public void Register(IHandleEvents handler) { lock (_subscribers) _subscribers.Add(handler); }
/// <summary> /// Remove a previously subscribed event handler. /// </summary> /// <param name="eventHandler"></param> public void Unsubscribe(IHandleEvents eventHandler) { _eventHandlers.Remove(eventHandler); }
public void Add(IHandleEvents eventHandler) { _receiver.Add(eventHandler); }
public IConcatenateEventHandler And(IHandleEvents eventHandler) { _receiver.Add(eventHandler); return(this); }
public void Add(IHandleEvents eventHandler) { _receiver.Add (eventHandler); }