コード例 #1
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    WebStoreContext context = services.GetRequiredService <WebStoreContext>();
                    DbInitializer.Initialize(context);
                    DbInitializer.InitializeUsers(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, message: "Oops... Something went wrong...");
                }
            }

            host.Run();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope()) // нужно для получения DbContext
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <WebStoreContext>();

                try
                {
                    DbInitializer.Initialize(context);
                    DbInitializer.InitializeUsers(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger>();
                    logger.LogError(ex, "OOps. Something went wrong...");
                }
            }

            host.Run();
        }