Esempio n. 1
0
 private static DomainEventsToDispatch[] FindDomainEvents(DomainDbContext domainDbContext) =>
 Enumerable.Empty <DomainEventsToDispatch>()
 .Append(FindDomainEvents <byte>(domainDbContext))
 .Append(FindDomainEvents <short>(domainDbContext))
 .Append(FindDomainEvents <ushort>(domainDbContext))
 .Append(FindDomainEvents <int>(domainDbContext))
 .Append(FindDomainEvents <uint>(domainDbContext))
 .Append(FindDomainEvents <long>(domainDbContext))
 .Append(FindDomainEvents <ulong>(domainDbContext))
 .Append(FindDomainEvents <Guid>(domainDbContext))
 .ToArray();
Esempio n. 2
0
        private static DomainEventsToDispatch FindDomainEvents <T>(DomainDbContext domainDbContext) where T : struct
        {
            var domainEntities = domainDbContext.ChangeTracker
                                 .Entries <AggregateRoot <T> >()
                                 .Where(x => x.Entity.DomainEvents.Any())
                                 .ToArray();

            var notifications = domainEntities
                                .SelectMany(x => x.Entity.DomainEvents)
                                .ToArray();

            return(new DomainEventsToDispatch
            {
                DomainEvents = notifications,
                ClearDomainEvents = () =>
                {
                    foreach (var entity in domainEntities)
                    {
                        entity.Entity.ClearDomainEvents();
                    }
                }
            });
        }