60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using SlpModularCms.Api.Extensions;
|
|
using SlpModularCms.Api.Infrastructure;
|
|
using Scalar.AspNetCore;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Load local developer overrides
|
|
builder.Configuration.AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: true);
|
|
|
|
// 1. Initialize Module Orchestrator
|
|
var loggerFactory = LoggerFactory.Create(lb => lb.AddConsole());
|
|
var orchestrator = new ModuleOrchestrator(loggerFactory.CreateLogger<ModuleOrchestrator>());
|
|
orchestrator.DiscoverModules();
|
|
|
|
// 2. Add Core Infrastructure
|
|
builder.Services.AddCoreInfrastructure(builder.Configuration);
|
|
builder.Services.AddCmsCors(builder.Configuration);
|
|
builder.Services.AddCmsRateLimiting(builder.Configuration);
|
|
|
|
// 3. Add Module Services
|
|
orchestrator.RegisterModuleServices(builder.Services);
|
|
|
|
// 4. Global Controller Configuration with Conventions
|
|
builder.Services.AddControllers(options =>
|
|
{
|
|
options.Conventions.Add(new ApiPrefixConvention("api/v1"));
|
|
})
|
|
.AddJsonOptions(options =>
|
|
{
|
|
options.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// 5. Global Exception Handling
|
|
app.UseExceptionHandler();
|
|
|
|
app.UseRateLimiter();
|
|
|
|
// 6. Configure Pipeline
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
app.MapScalarApiReference();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseCors();
|
|
|
|
// 7. Use Module Middleware
|
|
orchestrator.UseModules(app);
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|