2026-05-11 14:35:34 +08:00
|
|
|
|
using Avalonia_API.Configuration;
|
|
|
|
|
|
using Avalonia_API.Extensions;
|
|
|
|
|
|
using Avalonia_Common.Infrastructure;
|
|
|
|
|
|
using Avalonia_EFCore.Database;
|
|
|
|
|
|
using Avalonia_Services.Core;
|
|
|
|
|
|
using Avalonia_Services.Database;
|
|
|
|
|
|
using Serilog;
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化日志系统
|
|
|
|
|
|
Log.Logger = LoggingConfiguration.CreateDefaultLogger(logDir: "logs");
|
|
|
|
|
|
Log.Information("Avalonia-API 正在启动...");
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// 使用 Serilog 作为日志提供程序
|
|
|
|
|
|
builder.Host.UseSerilog();
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
|
builder.Services.AddOpenApi();
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// 注册统一端点及业务服务(入口在 Avalonia-Services/Endpoints/AppEndpoints.cs)
|
|
|
|
|
|
builder.Services.AddUnifiedApiServices();
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化数据库(自动迁移 + 种子数据)
|
|
|
|
|
|
app.Services.InitializeDatabase<AppDataContext>();
|
|
|
|
|
|
|
|
|
|
|
|
// 启动时打印所有接口
|
|
|
|
|
|
var endpoints = app.Services.GetRequiredService<ServiceEndpointCollection>();
|
|
|
|
|
|
EndpointPrinter.PrintEndpoints(endpoints, "Avalonia-API 接口列表");
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
|
{
|
|
|
|
|
|
app.MapOpenApi();
|
|
|
|
|
|
}
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
app.UseAuthorization();
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// 将统一端点映射到 ASP.NET Core 路由
|
|
|
|
|
|
app.MapUnifiedEndpoints(endpoints, app.Services);
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
2026-05-11 14:35:34 +08:00
|
|
|
|
app.Run();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Log.Fatal(ex, "Avalonia-API 启动失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Log.CloseAndFlush();
|
|
|
|
|
|
}
|