70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using API.Extension;
|
|
using Application.Extensions;
|
|
using Infrastructure.Context;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Utilities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.OpenApi;
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddWebServices(builder.Configuration);
|
|
builder.Services.AddInfrastructure(builder.Configuration);
|
|
builder.Services.AddApplication();
|
|
|
|
// PostgreSql Database for development
|
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
|
{
|
|
var postgreSqlSettings =
|
|
builder.Configuration.GetRequiredSection("PostgreSqlSettings").Get<PostgreSqlSettings>();
|
|
var connectionString = postgreSqlSettings?.ConnectionString;
|
|
options.UseNpgsql(connectionString);
|
|
});
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("AllowLocalhost",
|
|
policy =>
|
|
{
|
|
policy.WithOrigins("http://localhost:44492")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment() || app.Environment.IsEnvironment("Test"))
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseCors("AllowLocalhost");
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.MapControllers();
|
|
app.UseStaticFiles();
|
|
|
|
app.Run();
|
|
|
|
public class LowerCaseDocumentFilter : IDocumentFilter
|
|
{
|
|
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
|
{
|
|
// get the paths
|
|
var paths = swaggerDoc.Paths.ToDictionary(
|
|
path => path.Key.ToLowerInvariant(),
|
|
path => swaggerDoc.Paths[path.Key]);
|
|
|
|
// add the paths
|
|
swaggerDoc.Paths = new OpenApiPaths();
|
|
foreach (var pathItem in paths) swaggerDoc.Paths.Add(pathItem.Key, pathItem.Value);
|
|
}
|
|
}
|