Exemplo n.º 1
0
        //If you are handling the domain events right before committing the original transaction is because you want the side effects of those events to be included in the same transaction
        private async Task DispatchDomainEventsPreCommitAsync(
            Dictionary <object, List <IDomainEvent> > entityUpdatedEvents,
            Dictionary <object, List <IDomainEvent> > propertyUpdatedEvents,
            Dictionary <object, List <IDomainEvent> > entityDeletedEvents,
            Dictionary <object, List <IDomainEvent> > entityInsertedEvents,
            Dictionary <object, List <IDomainEvent> > entityDomainEvents
            )
        {
            foreach (var kvp in entityUpdatedEvents)
            {
                foreach (var domainEvent in kvp.Value)
                {
                    await _domainEvents.DispatchPreCommitAsync(domainEvent).ConfigureAwait(false);
                }

                //Property Update Events
                if (propertyUpdatedEvents != null && propertyUpdatedEvents.ContainsKey(kvp.Key))
                {
                    foreach (var propertyUpdateEvent in propertyUpdatedEvents[kvp.Key])
                    {
                        await _domainEvents.DispatchPreCommitAsync(propertyUpdateEvent).ConfigureAwait(false);
                    }
                }
            }

            foreach (var kvp in entityDeletedEvents)
            {
                foreach (var domainEvent in kvp.Value)
                {
                    await _domainEvents.DispatchPreCommitAsync(domainEvent).ConfigureAwait(false);
                }
            }

            foreach (var kvp in entityInsertedEvents)
            {
                foreach (var domainEvent in kvp.Value)
                {
                    await _domainEvents.DispatchPreCommitAsync(domainEvent).ConfigureAwait(false);
                }
            }

            foreach (var kvp in entityDomainEvents)
            {
                foreach (var domainEvent in kvp.Value)
                {
                    await _domainEvents.DispatchPreCommitAsync(domainEvent).ConfigureAwait(false);
                }
            }
        }