Esempio n. 1
0
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, SettlementContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

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

            if (domainEvents.Count == 0)
            {
                return;
            }

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.DomainEvents.Clear());


            //var tasks = domainEvents
            //    .Select(async (domainEvent) =>
            //    {
            //        await mediator.Publish(domainEvent);
            //    });
            domainEvents.ForEach(domainEvent =>
            {
                mediator.Publish(domainEvent).ConfigureAwait(true).GetAwaiter().GetResult();
            });
            //await Task.WhenAll(tasks);
            await Task.CompletedTask;
        }
Esempio n. 2
0
        public async Task SeedAsync(SettlementContext context, IHostingEnvironment env, ILogger <SettlementContextSeed> logger)
        {
            var policy = CreatePolicy(logger, nameof(SettlementContext));

            await policy.ExecuteAsync(async() =>
            {
                if (env.IsDevelopment())
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                    //if (!context.AssVehJobRelas.Any())
                    //{
                    //    context.AssVehJobRelas.AddRange(GetAssVehJobRelas());
                    //    await context.SaveChangesAsync();
                    //}
                }
                else
                {
                    context.Database.Migrate();
                }
            });
        }