添加项目文件。

This commit is contained in:
glz
2026-06-01 13:42:40 +08:00
parent 435474c5fe
commit bba985f937
56 changed files with 3758 additions and 0 deletions

View File

@ -0,0 +1,64 @@
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<GlobalExceptionMiddleware>();
builder.Services.AddTransient<OperationLogMiddleware>();
// 注册业务服务
builder.Services.AddScoped<QYZH.InteractiveMagazine.IService.IAuthService, QYZH.InteractiveMagazine.Service.AuthService>();
builder.Services.AddScoped<QYZH.InteractiveMagazine.IService.IWeChatMiniProgramService, QYZH.InteractiveMagazine.Service.WeChatMiniProgramService>();
// 初始化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<GlobalExceptionMiddleware>();
app.UseMiddleware<OperationLogMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();