/// <summary> /// subscribe domain event in global area /// </summary> /// <typeparam name="Event"></typeparam> /// <param name="eventHandleOperationAsync">event handle operation</param> /// <param name="executeTime">execute time</param> public void SubscribeAll(Func <IDomainEvent, Task <DomainEventExecuteResult> > eventHandleOperationAsync, EventTriggerTime executeTime = EventTriggerTime.Immediately) { IDomainEventHandler domainEventHandler = null; switch (executeTime) { case EventTriggerTime.Immediately: domainEventHandler = new DefaultImmediatelyDomainEventHandler <IDomainEvent>() { ExecuteEventOperation = eventHandleOperationAsync }; break; case EventTriggerTime.WorkCompleted: domainEventHandler = new DefaultWorkCompletedDomainEventHandler <IDomainEvent>() { ExecuteEventOperation = eventHandleOperationAsync }; break; } SubscribeAll(domainEventHandler); }
/// <summary> /// Subscribe domain event /// </summary> /// <typeparam name="TEvent">Domain event</typeparam> /// <param name="eventHandleOperation">event handle operation</param> /// <param name="executeTime">Execute time</param> public void Subscribe <TEvent>(Func <TEvent, DomainEventExecuteResult> eventHandleOperation, EventTriggerTime executeTime = EventTriggerTime.Immediately) where TEvent : class, IDomainEvent { IDomainEventHandler domainEventHandler = null; switch (executeTime) { case EventTriggerTime.Immediately: domainEventHandler = new DefaultImmediatelyDomainEventHandler <TEvent>() { ExecuteEventOperation = eventHandleOperation }; break; case EventTriggerTime.WorkCompleted: domainEventHandler = new DefaultWorkCompletedDomainEventHandler <TEvent>() { ExecuteEventOperation = eventHandleOperation }; break; } Subscribe <TEvent>(domainEventHandler); }