DAS_2024_1/yakovleva_yulia_lab_3/Buyer/Buyer/Startup.cs
2024-10-08 16:30:55 +04:00

51 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Buyer.DataBase;
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContext<BuyerDataBaseContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("BuyerDatabase")));
services.AddSwaggerGen();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceScopeFactory serviceScopeFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
using (var scope = serviceScopeFactory.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<BuyerDataBaseContext>();
context.Database.Migrate();
}
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSwagger();
app.UseSwaggerUI();
}
}