// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider).Wait(); app.UseCors(builder => builder.AllowAnyOrigin() //TODO ); app.UseAuthentication(); app.UseHttpsRedirection(); app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint(url: String.Format("/swagger/{0}/swagger.json", "JWTUygulamasiWebAPI-Swagger"), name: "Version CoreSwaggerWebAPI-1"); //c.DocExpansion(DocExpansion.None); }); }
// 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(); } if (env.IsEnvironment("Linux")) { var context = app.ApplicationServices.GetService <ApplicationDbContext>(); var seedDb = new SeedDb(context); seedDb.Run(); } app.UseCors(options => options.WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader()); app.UseRouting(); app.UseAuthorization(); app.UseAuthentication(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <IssueTrackerContext>(); context.Database.Migrate(); // requires using Microsoft.Extensions.Configuration; // Set password with the Secret Manager tool. // dotnet user-secrets set SeedUserPW <pw> var testUserPw = "!XtremaxProject123"; SeedDb.Initialize(services, testUserPw).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedDb seeder) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); seeder.SeedAsync().Wait(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SeedDb seed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(builder => { builder.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var error = context.Features.Get <IExceptionHandlerFeature>(); if (error != null) { context.Response.AddApplicationError(error.Error.Message); await context.Response.WriteAsync(error.Error.Message); } }); }); // app.UseHsts(); } seed.SeedUsers(); app.UseAuthentication(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); // app.UseHttpsRedirection(); app.UseMvc(); }
public DependencySetupFixture() { var serviceCollection = new ServiceCollection(); serviceCollection.AddDbContext <BankIssuerDbContext>(options => options.UseInMemoryDatabase("BankIssuer")); var options = new DbContextOptionsBuilder <BankIssuerDbContext>() .UseInMemoryDatabase(databaseName: "BankIssuer") .Options; using var context = new BankIssuerDbContext(options); context.Database.EnsureCreated(); SeedDb.Initialize(context); serviceCollection.AddScoped(typeof(IRepository <>), typeof(Repository <>)); serviceCollection.AddTransient <Master>(); serviceCollection.AddTransient <Visa>(); serviceCollection.AddTransient <Func <Origin, ICalculator> >(serviceProvider => key => { return(key switch { Origin.MASTER => serviceProvider.GetService <Master>(), Origin.VISA => serviceProvider.GetService <Visa>(), _ => throw new KeyNotFoundException() }); });
private static void RunSeeding(IHost host) { IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>(); using IServiceScope scope = scopeFactory.CreateScope(); SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>(); seeder.SeedAsync().Wait(); }
// 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(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseCors("EnableCORS"); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")), RequestPath = new PathString("/Resources") }); app.UseSpaStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); SeedDb.CreateConnection(app); app.UseMvc(); }
private static void RunSeeding(IWebHost host) { IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>(); seeder.SeedAsync().Wait(); //Wait, permite correr un mètodo no async en async } }
private static void RunSeeding(IWebHost host) { var scopeFactory = host.Services.GetService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>(); seeder.SeedAsync().Wait(); //Wait till data is added to DB for Testing } }
private static void RunSeeding(IWebHost host) { IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>(); try { seeder.SeedAsync().Wait(); } catch (Exception) { } } }
public AccountAPITest() { var options = new DbContextOptionsBuilder <BankIssuerDbContext>() .UseInMemoryDatabase(databaseName: "BankIssuer") .Options; using var context = new BankIssuerDbContext(options); context.Database.EnsureCreated(); SeedDb.Initialize(context); }
private void Seed(IApplicationBuilder app) { using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetService <IntellectDbContext>(); var userManager = scope.ServiceProvider.GetService <UserManager <ApplicationUser> >(); var roleManager = scope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); context.Database.Migrate(); SeedDb.Seed(context, userManager, roleManager).Wait(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, EfCoreSampleDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.EnsureContextMigrated <EfCoreSampleDbContext>(); //TODO change this seed method, remove EfCoreSampleDbContext from configure method SeedDb.Initialize(context);//ContextSeed.SeedAsync(app).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHangfireDashboard(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); app.UseAuthentication(); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseReactDevelopmentServer(npmScript: "start"); } }); }
private static void RunSeeding(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { SeedDb.Initialize(services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // ******************** // USE CORS - might not be required. // ******************** app.UseCors("SiteCorsPolicy"); app.UseAuthentication(); app.UseMvc(); SeedDb.InitDb(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { //3. Get the instance of BoardGamesDBContext in our services layer var services = scope.ServiceProvider; var context = services.GetRequiredService <BankIssuerDbContext>(); //4. Call the DataGenerator to create sample data SeedDb.Initialize(context); } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); // Instantiating the in-memory DB. using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <EzraAssessmentDbContext>(); SeedDb.Initialize(services); } AutoMapperConfig.Init(); host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, EfCoreSampleDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; }); app.UseMvc(); app.EnsureContextMigrated <EfCoreSampleDbContext>(); SeedDb.Initialize(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); var scopeFactory = host.Services.GetRequiredService <IServiceScopeFactory>(); using (var scope = scopeFactory.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService <AppDbContext>(); if (db.Database.EnsureCreated()) { SeedDb.Initialize(db); } } host.Run(); }
static async Task <int> Main(string[] args) //03-12-18 made async and returns int not void { MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures); MxReturnCode <int> rc = new MxReturnCode <int>("Main()", -1, "*****@*****.**"); try //03-12-18 { IWebHost host = CreateWebHostBuilder(args).Build(); //calls Startup.ConfigureServices() using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; if (services == null) { rc.SetError(3130101, MxError.Source.Sys, "scope.ServiceProvider is null"); } else { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var config = services.GetRequiredService <IConfiguration>(); if ((userManager == null) || (roleManager == null) || (config == null)) { rc.SetError(3130102, MxError.Source.Sys, "userManager or roleManager or config is null"); } else { var result = await SeedDb.EnsureDataPresentAsync(config, userManager, roleManager); rc += result; if (result.IsSuccess()) { host.Run(); //calls Startup.Configure() rc.SetResult(0); //success - webapp has completed } } } } } catch (Exception e) { rc.SetError(3010103, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true); } return(rc.GetResult()); //03-12-18 }
// 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(); } SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// 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(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action}"); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer("start"); } }); SeedDb.CreateConnection(app); }
public static void Main(string[] args) { var host = CreateHostBuilder(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); SeedDb.CreateRoles(serviceProvider).Wait(); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "An error occurred while creating roles"); } } host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { try { var recipesDbContext = scope.ServiceProvider.GetRequiredService <RecipesDbContext>(); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <AppUser> >(); recipesDbContext.Database.Migrate(); SeedDb.SeedAsync(recipesDbContext, userManager).Wait(); } catch (Exception ex) { scope.ServiceProvider.GetRequiredService <ILogger>().LogError(ex, "Error running the app"); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "NET5.JWT.CustomUser v1")); context.Database.EnsureCreated(); SeedDb.Initialize(context).Wait(); } app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } SeedDb.InitializeDb(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); app.UseHttpsRedirection(); app.UseAuthentication(); // For Angular client app.UseCors(builder => builder .WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader()); app.UseMvc(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); try { SeedDb.Initialize(context, userManager, roleManager).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebDbContext webDbContext, IServiceProvider serviceProvider) { webDbContext.Database.EnsureCreated(); SeedDb.Initialize(serviceProvider); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestWebApi v1")); } SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); }