private static void SeedDatabase(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; var context = services.GetRequiredService <UsersWebApiContext>(); UsersContextSeed.SeedAsync(context); }
public void PrepareDatabase(IApplicationBuilder app, ILoggerFactory loggerFactory) { try { using (var scope = app.ApplicationServices.CreateScope()) { var settings = scope.ServiceProvider.GetRequiredService <IOptions <UserSettings> >(); var context = new MongoContext(settings); var usersContextSeed = new UsersContextSeed(context); usersContextSeed.SeedAsync(app, loggerFactory).Wait(); } } catch (Exception exception) { throw exception; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); UsersContextSeed.SeedAsync(app).Wait(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseCors("CorsPolicy"); app.UseMvcWithDefaultRoute(); app.UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sfeir puppy API V1"); c.OAuthClientId("usersswaggerui"); c.OAuthAppName("Users Swagger UI"); }); // Seed Data UsersContextSeed.SeedAsync(app, loggerFactory).Wait(); }