autobus-api_old/AutobusApi.Api/Program.cs

66 lines
1.7 KiB
C#

using AutobusApi.Infrastructure;
using AutobusApi.Application;
using AutobusApi.Api.Middlewares;
using AutoubsApi.Infrastructure.Data;
using AutobusApi.Infrastructure.Identity;
using Microsoft.OpenApi.Models;
using AutobusApi.Api.OpenApi;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddApplication();
builder.Services.AddControllers();
builder.Services.AddSwaggerGen(options =>
{
options.SchemaFilter<TimeSpanSchemaFilter>();
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Scheme = "Bearer",
BearerFormat = "Jwt",
In = ParameterLocation.Header,
Name = "Authorization",
Description = "Bearer Authentication With Jwt",
Type = SecuritySchemeType.Http
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Id = "Bearer",
Type = ReferenceType.SecurityScheme
}
},
new List<string>()
}
});
});
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 { }