Exemple #1
0
        public static async Task Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();
            await WebApplicationInitializer.InitializeAsync(host);

            await host.RunAsync();
        }
 public void InitializeDb(IApplicationBuilder app, IHostingEnvironment env)
 {
     using (var scope = app.ApplicationServices.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <WebApplicationDbContext>();
             WebApplicationInitializer.Initialize(context);
             if (!context.Users.Any(x => x.Username == "admin"))
             {
                 var passwordHasher = services.GetRequiredService <IPasswordHasher <User> >();
                 var user           = new User
                 {
                     Username = "******",
                 };
                 user.Password = passwordHasher.HashPassword(user, "admin");
                 context.Users.Add(user);
                 context.SaveChanges();
             }
         }
         catch (Exception ex)
         {
         }
     }
 }