Example #1
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var context = scope.ServiceProvider.GetService <IContactDbContext>();

                    var concreteContext = (ContactDbContext)context;
                    concreteContext.Database.Migrate();
                    ContactInitializer.Initialize(concreteContext);
                }
                catch (Exception ex)
                {
                    var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while migrating or initializing the database.");
                }
            }

            host.Run();
        }
Example #2
0
 public static void InitializeDbForTests(ContactDbContext context)
 {
     ContactInitializer.Initialize(context);
 }