51 lines
1.2 KiB
C#
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();
|
|
}
|
|
}
|