using QYZH.InteractiveMagazine.Infrastructure.Extensions; using QYZH.InteractiveMagazine.Infrastructure.Middleware; using QYZH.InteractiveMagazine.Repository; using Serilog; var builder = WebApplication.CreateBuilder(args); // 配置Serilog Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); builder.Host.UseSerilog(); // 注册服务 builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // 基础设施服务注册(JWT、Redis、RabbitMQ) builder.Services.AddInfrastructureServices(builder.Configuration); // 注册中间件 builder.Services.AddTransient(); builder.Services.AddTransient(); // 注册业务服务 builder.Services.AddScoped(); builder.Services.AddScoped(); // 初始化SqlSugar SqlSugarDbContext.Init(builder.Configuration); // 添加CORS builder.Services.AddCors(options => { options.AddPolicy("AllowAll", policy => { policy.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); var app = builder.Build(); // 配置HTTP请求管道 if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseCors("AllowAll"); app.UseMiddleware(); app.UseMiddleware(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();