コード例 #1
0
        /// <summary>
        /// 处理领域事件
        /// </summary>
        /// <param name="eventSource">领域事件源</param>
        /// <remarks>此方法涉及反射操作,慎做修改</remarks>
        public static void Handle(IEvent eventSource)
        {
            //获取相应事件处理者实例集合
            IEnumerable <IEventHandler> eventHandlers = EventHandlerFactory.GetEventHandlersFor(eventSource.GetType()).OrderByDescending(x => x.Sort);

            //顺序处理事件
            foreach (IEventHandler handler in eventHandlers)
            {
                try
                {
                    Type handlerType = handler.GetType();

                    MethodInfo methodInfo = handlerType.GetMethod("Handle", new[] { eventSource.GetType() });
                    methodInfo?.Invoke(handler, new object[] { eventSource });
                }
                catch (TargetInvocationException ex)
                {
                    if (ex.InnerException != null)
                    {
                        throw ex.InnerException;
                    }
                    throw;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 处理领域事件
        /// </summary>
        /// <typeparam name="T">领域事件类型</typeparam>
        /// <param name="eventSource">领域事件源</param>
        public static void Handle <T>(T eventSource) where T : class, IEvent
        {
            //获取相应事件处理者实例集合
            IEnumerable <IEventHandler <T> > eventHandlers = EventHandlerFactory.GetEventHandlersFor(eventSource);

            foreach (IEventHandler <T> handler in eventHandlers)
            {
                handler.Handle(eventSource);
            }
        }
コード例 #3
0
        /// <summary>
        /// 处理领域事件
        /// </summary>
        /// <typeparam name="T">领域事件类型</typeparam>
        /// <param name="eventSource">领域事件源</param>
        public static void Handle <T>(T eventSource) where T : class, IEvent
        {
            //获取相应事件处理者实例集合
            IEnumerable <IEventHandler <T> > eventHandlers = EventHandlerFactory.GetEventHandlersFor(eventSource).OrderByDescending(x => x.Sort);

            //顺序处理事件
            foreach (IEventHandler <T> handler in eventHandlers)
            {
                handler.Handle(eventSource);
            }
        }