Beispiel #1
0
        public static async Task PublicarEventos(this IMediator mediator, VendasContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.Notificacoes != null && x.Entity.Notificacoes.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.Notificacoes)
                               .ToList();

            domainEntities.ToList()
            .ForEach(x => x.Entity.LimparEvento());

            var task = domainEvents.Select(async(domainEvent) => { await mediator.Publish(domainEvent); });
            await Task.WhenAll(task);
        }
        public static async Task PublicarEventos(this IMediatorHandler mediator, VendasContext context)
        {
            var domainEntities = context.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(e => e.Entity.Notificacoes != null && e.Entity.Notificacoes.Any());

            var domainEvents = domainEntities
                               .SelectMany(e => e.Entity.Notificacoes)
                               .ToList();

            domainEntities.ToList()
            .ForEach(e => e.Entity.LimparEventos());

            var tasks = domainEvents
                        .Select(async(domainEvent) =>
            {
                await mediator.PublicarEvento(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
        public static async Task PublicarEventos(this IMediatorHandler mediator, VendasContext ctx)
        {
            // ChangeTracker = PEGA AQUILO QUE EU MODIFIQUEI
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.Notificacoes != null && x.Entity.Notificacoes.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.Notificacoes)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.LimparEventos());

            var tasks = domainEvents
                        .Select(async(domainEvent) => {
                await mediator.PublicarEvento(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
Beispiel #4
0
        public static async Task PublicarEventos(this IMediatrHandler mediator, VendasContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.Notificacoes != null && x.Entity.Notificacoes.Any());

            var entityEntries = domainEntities as EntityEntry <Entity>[] ?? domainEntities.ToArray();

            var domainEvents = entityEntries
                               .SelectMany(x => x.Entity.Notificacoes)
                               .ToList();

            entityEntries.ToList()
            .ForEach(entity => entity.Entity.LimparEventos());

            var tasks = domainEvents
                        .Select(async(domainEvent) => {
                await mediator.PublicarEvento(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
        public static async Task PublicarEventos(this IMediator mediator, VendasContext ctx)
        {
            //pega todos os eventos das entitades, limpa-os, e publica um a um

            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.Notificacoes != null && x.Entity.Notificacoes.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.Notificacoes)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.LimparEventos());

            var tasks = domainEvents
                        .Select(async(domainEvent) =>
            {
                await mediator.Publish(domainEvents);
            });

            await Task.WhenAll(tasks);
        }