コード例 #1
0
        public void Publish <T>(T @event) where T : IDomainEvent
        {
            var handlers = _eventHandlerFactory.GetHandlers(@event);

            if (handlers == null)
            {
                return;
            }

            foreach (var handler in handlers)
            {
                handler.Handle(@event);
            }
        }
        private IDomainEventHandlerCollection GetHandlers(IDomainEvent domainEvent)
        {
            Contract.Requires(domainEvent != null);
            Contract.Ensures(Contract.Result <IDomainEventHandlerCollection>() != null);

            try
            {
                // get handler from factory
                return(_handlerFactory.GetHandlers(domainEvent.GetType()));
            }
            catch (Exception e)
            {
                // throw exception as a domain event handling exception
                throw new DomainEventHandlingException(domainEvent, e, "Could not get a domain event handler for domain event.");
            }
        }
 public void CanGetHandlerForRegisteredDomainEvent()
 {
     Assert.IsNotNull(_factory.GetHandlers(typeof(DomainEvent1)));
 }