コード例 #1
0
        private void DispatchDomainEvents()
        {
            var domainEventEntities = _dataContext.ChangeTracker.Entries <Entity>()
                                      .Select(po => po.Entity)
                                      .Where(po => po.DomainEvents != null && po.DomainEvents.Any())
                                      .ToArray();

            foreach (var entity in domainEventEntities.ToArray())
            {
                var events = entity.DomainEvents.ToArray();
                entity.ClearDomainEvents();
                foreach (var domainEvent in events)
                {
                    _mediatorService.Dispatch(domainEvent);
                }
            }
        }