72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using Microsoft.OpenApi.Models;
|
|
using ExpenseTracker.Api.Middlewares;
|
|
using ExpenseTracker.Infrastructure;
|
|
using ExpenseTracker.Application;
|
|
using ExpenseTracker.Persistence;
|
|
using ExpenseTracker.Infrastructure.Identity;
|
|
using ExpenseTracker.Api.Services;
|
|
using ExpenseTracker.Application.Common.Interfaces.Services;
|
|
using ExpenseTracker.Api.Swashbuckle.OperationFilters;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
builder.Services.AddPersistence(builder.Configuration);
|
|
builder.Services.AddInfrastructure(builder.Configuration);
|
|
builder.Services.AddApplication();
|
|
|
|
builder.Services.AddAuthorization();
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddSwaggerGen(options =>
|
|
{
|
|
options.OperationFilter<AcceptCurrencyHeaderFilter>();
|
|
options.EnableAnnotations();
|
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
|
{
|
|
Scheme = "Bearer",
|
|
BearerFormat = "Json Web Token",
|
|
In = ParameterLocation.Header,
|
|
Name = "Authorization",
|
|
Description = "Bearer Authentication With Json Web Token",
|
|
Type = SecuritySchemeType.Http
|
|
});
|
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference
|
|
{
|
|
Id = "Bearer",
|
|
Type = ReferenceType.SecurityScheme
|
|
}
|
|
},
|
|
new List<string>()
|
|
}
|
|
});
|
|
});
|
|
|
|
builder.Services.AddTransient<GlobalExceptionHandlerMiddleware>();
|
|
builder.Services.AddScoped<ISessionUserService, SessionUserService>();
|
|
builder.Services.AddScoped<IInternationalizationService, InternationalizationService>();
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
|
|
|
|
app.MapControllers();
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
|
|
var scope = app.Services.CreateScope();
|
|
IdentitySeeder.SeedIdentity(scope);
|
|
|
|
app.Run();
|