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 }));
        }
Пример #2
0
 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));
        }
Пример #4
0
        public void Subscribe(IHandleEvents eventHandler, Type ofEventIHandle)
        {
            if (!_registry.ContainsKey(ofEventIHandle))
            {
                _registry.Add(ofEventIHandle, new List <IHandleEvents>());
            }

            var handlers = _registry[ofEventIHandle];

            handlers.Add(eventHandler);
        }
Пример #5
0
        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 });
            }
        }
Пример #6
0
        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 });
            }
        }
Пример #7
0
 public ReceiveMessage(IHandleEvents salesEventHandler)
 {
     _salesEventHandler = salesEventHandler;
 }
Пример #8
0
        public IConcatenateEventHandler And(IHandleEvents eventHandler)
        {
            _receiver.Add (eventHandler);

            return this;
        }
Пример #9
0
 /// <summary>
 /// Register or reregister an event handler.
 /// </summary>
 public void Subscribe(IHandleEvents eventHandler, ISelectEvents eventFilter = null)
 {
     eventFilter = eventFilter ?? DelegateSelector.Any;
     _eventHandlers[eventHandler] = eventFilter;
 }
Пример #10
0
        public IConcatenateEventHandler PublishNewStateTo(IHandleEvents eventHandler)
        {
            _eventHandlers.Add(eventHandler);

            return(_eventHandlers);
        }
 public void Unregister(IHandleEvents handler)
 {
 }
Пример #12
0
 public void To(IHandleEvents eventHandler)
 {
     eventHandler.Receive(_currentAggregateEvents);
 }
Пример #13
0
 public void Unregister(IHandleEvents handler)
 {
     lock (_subscribers)
         _subscribers.Remove(handler);
 }
Пример #14
0
 public void Register(IHandleEvents handler)
 {
     lock (_subscribers)
         _subscribers.Add(handler);
 }
Пример #15
0
 /// <summary>
 /// Remove a previously subscribed event handler.
 /// </summary>
 /// <param name="eventHandler"></param>
 public void Unsubscribe(IHandleEvents eventHandler)
 {
     _eventHandlers.Remove(eventHandler);
 }
Пример #16
0
 public void Add(IHandleEvents eventHandler)
 {
     _receiver.Add(eventHandler);
 }
Пример #17
0
        public IConcatenateEventHandler And(IHandleEvents eventHandler)
        {
            _receiver.Add(eventHandler);

            return(this);
        }
Пример #18
0
 public void Add(IHandleEvents eventHandler)
 {
     _receiver.Add (eventHandler);
 }