コード例 #1
0
ファイル: Program.cs プロジェクト: FaierAndreea/Bijuteria-Eve
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = services.GetRequiredService <GemsContext>();
                    await context.Database.MigrateAsync();

                    await SeedDataClass.SeedAsync(context, loggerFactory);

                    var userManager     = services.GetRequiredService <UserManager <AppUser> >();
                    var identityContext = services.GetRequiredService <IdentityContext>();
                    await identityContext.Database.MigrateAsync();

                    await IdentitySeed.SeedUserAsync(userManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
コード例 #2
0
 public CustomWebApplicationFactory(SeedDataClass seed)
 {
     if (seed == null)
     {
         throw new ArgumentNullException(nameof(seed));
     }
     _seed = seed;
 }