autobus-api_old/AutobusApi.Api/Program.cs
2023-11-15 19:00:34 +02:00

38 lines
980 B
C#

using AutobusApi.Infrastructure;
using AutobusApi.Application;
using AutobusApi.Api.Middlewares;
using AutoubsApi.Infrastructure.Data;
using AutobusApi.Infrastructure.Identity;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddApplication();
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();
builder.Services.AddTransient<GlobalExceptionHandlerMiddleware>();
var app = builder.Build();
// Initialize database
var scope = app.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
var identityDbContext = scope.ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>();
DbInitializer.Initialize(dbContext, identityDbContext);
app.UseAuthentication();
app.MapControllers();
app.UseSwagger();
app.UseSwaggerUI();
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
app.Run();
public partial class Program { }