public async Task SeedAsync(SmartBlogMySqlDbContext context, ILoggerManager loggerManager)
        {
            using (context)
            {
                context.Database.Migrate();

                //if (await context.SysConfigs.AnyAsync(s => s.ParamKey == "Default_Avatar_Url") == false)
                //{
                //    context.SysConfigs.Add(new SysConfig { ParamKey = "Default_Avatar_Url",
                //        ParamValue = "http://pic.qqtn.com/up/2018-3/15198831325527845.jpg",
                //        Remark = "默认头像Url" });
                //    loggerManager.Info("系统配置表添加key:Default_Avatar_Url");
                //}
                //await context.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, SmartBlogMySqlDbContext 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();

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

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

            await Task.WhenAll(tasks);
        }