|
|
@ -31,7 +31,7 @@ var builder = WebApplication.CreateBuilder(args); |
|
|
builder.Services.AddEndpoints(); |
|
|
builder.Services.AddEndpoints(); |
|
|
|
|
|
|
|
|
//Use to force loading of appsettings.json of test project
|
|
|
//Use to force loading of appsettings.json of test project
|
|
|
builder.Configuration.AddConfigurationFile(); |
|
|
builder.Configuration.AddConfigurationFile("appsettings.test.json"); |
|
|
builder.Logging.AddConsole(); |
|
|
builder.Logging.AddConsole(); |
|
|
|
|
|
|
|
|
Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services); |
|
|
Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services); |
|
|
@ -129,6 +129,27 @@ var app = builder.Build(); |
|
|
|
|
|
|
|
|
app.Logger.LogInformation("PublicApi App created..."); |
|
|
app.Logger.LogInformation("PublicApi App created..."); |
|
|
|
|
|
|
|
|
|
|
|
app.Logger.LogInformation("Seeding Database..."); |
|
|
|
|
|
|
|
|
|
|
|
using (var scope = app.Services.CreateScope()) |
|
|
|
|
|
{ |
|
|
|
|
|
var scopedProvider = scope.ServiceProvider; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var catalogContext = scopedProvider.GetRequiredService<CatalogContext>(); |
|
|
|
|
|
await CatalogContextSeed.SeedAsync(catalogContext, app.Logger); |
|
|
|
|
|
|
|
|
|
|
|
var userManager = scopedProvider.GetRequiredService<UserManager<ApplicationUser>>(); |
|
|
|
|
|
var roleManager = scopedProvider.GetRequiredService<RoleManager<IdentityRole>>(); |
|
|
|
|
|
var identityContext = scopedProvider.GetRequiredService<AppIdentityDbContext>(); |
|
|
|
|
|
await AppIdentityDbContextSeed.SeedAsync(identityContext, userManager, roleManager); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
app.Logger.LogError(ex, "An error occurred seeding the DB."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment()) |
|
|
if (app.Environment.IsDevelopment()) |
|
|
{ |
|
|
{ |
|
|
app.UseDeveloperExceptionPage(); |
|
|
app.UseDeveloperExceptionPage(); |
|
|
@ -159,26 +180,6 @@ app.UseEndpoints(endpoints => |
|
|
endpoints.MapControllers(); |
|
|
endpoints.MapControllers(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
app.Logger.LogInformation("Seeding Database..."); |
|
|
|
|
|
|
|
|
|
|
|
using (var scope = app.Services.CreateScope()) |
|
|
|
|
|
{ |
|
|
|
|
|
var scopedProvider = scope.ServiceProvider; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var catalogContext = scopedProvider.GetRequiredService<CatalogContext>(); |
|
|
|
|
|
await CatalogContextSeed.SeedAsync(catalogContext, app.Logger); |
|
|
|
|
|
|
|
|
|
|
|
var userManager = scopedProvider.GetRequiredService<UserManager<ApplicationUser>>(); |
|
|
|
|
|
var roleManager = scopedProvider.GetRequiredService<RoleManager<IdentityRole>>(); |
|
|
|
|
|
await AppIdentityDbContextSeed.SeedAsync(userManager, roleManager); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
app.Logger.LogError(ex, "An error occurred seeding the DB."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.MapEndpoints(); |
|
|
app.MapEndpoints(); |
|
|
app.Logger.LogInformation("LAUNCHING PublicApi"); |
|
|
app.Logger.LogInformation("LAUNCHING PublicApi"); |
|
|
app.Run(); |
|
|
app.Run(); |
|
|
|