// 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); }); }
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() }); });
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 AccountAPITest() { var options = new DbContextOptionsBuilder <BankIssuerDbContext>() .UseInMemoryDatabase(databaseName: "BankIssuer") .Options; using var context = new BankIssuerDbContext(options); context.Database.EnsureCreated(); SeedDb.Initialize(context); }
// 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"); } }); }
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(); }
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."); } } }
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(); }
// 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, 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(); }); }
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"); } }); }
public void ConfigureServices(IServiceCollection services) { services.AddServerSideBlazor(); services.AddControllersWithViews().AddCoreXF(services, this.Configuration); services.AddDbContext <UsersDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <UsersDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.SaveToken = true; options.RequireHttpsMetadata = false; options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidAudience = "https://codesolidi.com", ValidIssuer = "https://www.codesolidi.com", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("7S79jvOkEdwoRqHx")) }; }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <SwaggerSelector>(_ => SwaggerSelector.Service); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(setup => { setup.DocInclusionPredicate((name, x) => { var provider = services.BuildServiceProvider(); var selector = provider.GetRequiredService <SwaggerSelector>(); return(selector.IncludeDocument(x)); }); setup.SwaggerDoc(name: "v3", new OpenApiInfo { Title = "CoreXF APIs", Version = "v3", }); setup.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = SecuritySchemeType.ApiKey }); setup.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] { } } }); }); SeedDb.Initialize(services.BuildServiceProvider()); }