Example #1
0
        public static async Task <int> Main(string[] args)
        {
            ConfigureLogging();

            // Get the IWebHost which will host this application.
            var host = CreateHostBuilder(args).Build();

            // Find the service layer within our scope.
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    Log.Logger.Information("starting application...");

                    // Get the instance of appDbcontext in our services layer
                    var context     = services.GetRequiredService <AppDbContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    await context.Database.MigrateAsync(); //applies any pending migration to the context

                    await IdentitySeed.SeedUsersData(userManager);

                    // Continue to run the application
                    host.Run();

                    return(0);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "application terminated unexpectedly");
                    return(1);
                }
                finally
                {
                    Log.CloseAndFlush();
                }
            }
        }