Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            IWebHost host = BuildWebHost(args);

            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider services = scope.ServiceProvider;
                UserManager <ApplicationUser> userManager =
                    services.GetRequiredService <UserManager <ApplicationUser> >();

                try
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    Task rolesTask    = SeedRoles.Initialize(services, userManager);
                    Task productsTask = SeedProducts.Initialize(services);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                    // Spinlock until seeding is complete (there is surely a better way to do this?)
                    while (!rolesTask.IsCompleted || !productsTask.IsCompleted)
                    {
                    }
                }
                catch
                {
                    Console.Error.WriteLine(
                        "Could not seed database with admin user and roles.");
                    throw;
                }
            }

            host.Run();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // CreateHostBuilder(args).Build().Run();
            var host = CreateWebHostBuilder(args).Build();

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

                try
                {
                    var context     = sp.GetRequiredService <DataContext>();
                    var userManager = sp.GetRequiredService <UserManager <AppUser> >();

                    context.Database.Migrate();
                    SeedUser.Initialize(context, userManager).Wait();
                    SeedProducts.Initialize(context).Wait();
                    SeedVoucherCode.Initialize(context).Wait();
                }
                catch (Exception err)
                {
                    var logger = sp.GetRequiredService <ILogger <Program> >();
                    logger.LogError(err, "Error migrating database");
                }
            }

            host.Run();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services    = scope.ServiceProvider;
                var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();

                SeedMemberRoles.SeedData(services, userManager);
                SeedProducts.Initialize(services);
            }
            host.Run();
        }