Пример #1
0
        /// <summary>
        /// Raises a new domain event. Ideally call it within a domain entity code to express that a certain
        /// domain behavior has happened.
        /// </summary>
        /// <typeparam name="TDomainEvent">A domain event type</typeparam>
        /// <param name="domainEvent">A domain event instance</param>
        public static void RaiseEvent <TDomainEvent>(TDomainEvent domainEvent) where TDomainEvent : IDomainEvent
        {
            _CheckWasInitialized();

            if (_isDelayedDomainEventHandlingEnabled)
            {
                _RegisterDelayedEvent(domainEvent);
            }
            else
            {
                _raiseEventNow();
            }

            void _raiseEventNow()
            {
                var domainEventHandlers = _domainEventHandlerFactory.Create <TDomainEvent>().ToList();

                try
                {
                    domainEventHandlers.Each(domainEventHandler => domainEventHandler.Handle(domainEvent));
                }
                finally
                {
                    domainEventHandlers.Each(_domainEventHandlerFactory.Release);
                }
            }
        }
Пример #2
0
            public void Publish(DomainEvent domainEvent)
            {
                var exceptionList = new List <Exception>();

                var handleMethod = typeof(IHandleDomainEvents <>).MakeGenericType(domainEventType).GetMethod("Handle");

                foreach (var eventHandlerType in eventHandlerTypes)
                {
                    try
                    {
                        var eventHandler = eventHandlerFactory.Create(eventHandlerType);
                        handleMethod.Invoke(eventHandler, new object[] { domainEvent });
                    }
                    catch (Exception exception)
                    {
                        logger.Error(string.Format("An exception occured while handling event of type '{0}'\nMessage: {1}", domainEvent.GetType(), exception.Message), exception);
                        exceptionList.Add(exception);
                    }
                }

                if (exceptionList.Count > 0)
                {
                    throw new AggregateException(exceptionList);
                }
            }
Пример #3
0
            public void Publish(DomainEvent domainEvent)
            {
                var handleMethod = typeof(IHandleDomainEvents <>).MakeGenericType(domainEventType).GetMethod("Handle");

                foreach (var eventHandlerType in eventHandlerTypes)
                {
                    var eventHandler = eventHandlerFactory.Create(eventHandlerType);
                    handleMethod.Invoke(eventHandler, new object[] { domainEvent });
                }
            }