public DomainEventHandlerMessage(string handlerType, DomainEventMessage domainEventMessage)
 {
     Id                 = Guid.NewGuid();
     CreationDate       = DateTime.UtcNow;
     HandlerType        = handlerType;
     DomainEventMessage = domainEventMessage;
 }
 public DomainEventHandlerMessage(Guid id, DateTime createDate, string handlerType, DomainEventMessage domainEventMessage)
 {
     Id                 = id;
     CreationDate       = createDate;
     HandlerType        = handlerType;
     DomainEventMessage = domainEventMessage;
 }
        public virtual async Task DispatchPostCommitAsync(IDomainEvent domainEvent)
        {
            var domainEventMessage = new DomainEventMessage("", domainEvent);

            try
            {
                await HandlePostCommitDispatchAsync(domainEventMessage).ConfigureAwait(false);
            }
            catch
            {
                //Log InProcess Post commit event failed
            }
        }
        public override Task DispatchPostCommitAsync(IDomainEvent domainEvent)
        {
            var domainEventMessage = new DomainEventMessage(_serverSettings.ServerName, domainEvent);

            try
            {
                var job   = Job.FromExpression <IDomainEventsMediator>(m => m.HandlePostCommitDispatchAsync(domainEventMessage));
                var queue = new EnqueuedState(_serverSettings.ServerName);
                _backgroundJobClient.Create(job, queue);
            }
            catch
            {
                //Log Hangfire Post commit event Background enqueue failed
            }

            return(Task.CompletedTask);
        }
        //Event Dispatcher
        public async Task HandlePostCommitDispatchAsync(DomainEventMessage domainEventMessage)
        {
            var handlerTypes = _domainEventSubscriptionsManager.GetHandlersForEvent(domainEventMessage.DomainEvent);

            if (DispatchPostCommitEventsInParellel)
            {
                await Task.Run(() => Parallel.ForEach(handlerTypes, async handlerType =>
                {
                    var domainEventHandlerMessage = new DomainEventHandlerMessage(handlerType.HandlerType.FullName, domainEventMessage);
                    await TryDispatchHandlerPostCommitAsync(domainEventHandlerMessage).ConfigureAwait(false);
                }));
            }
            else
            {
                foreach (var handlerType in handlerTypes)
                {
                    var domainEventHandlerMessage = new DomainEventHandlerMessage(handlerType.HandlerType.FullName, domainEventMessage);
                    await TryDispatchHandlerPostCommitAsync(domainEventHandlerMessage).ConfigureAwait(false);
                }
            }
        }