- 将 AppDataContext、实体模型、Migrations 从 Avalonia-Services 移动到 Avalonia-EFCore - 更新 API、PC、Services 中的数据库上下文和实体引用命名空间 - 在实体上显式绑定表名、字段名和数据库注释 - 更新 InitialCreate、Designer、Snapshot,使用新的表名、字段名和注释 - 新增 AppDataContextFactory,支持 dotnet ef 设计时创建 DbContext - 新增本地 dotnet-ef 工具清单 - 新增一键生成迁移脚本 add-migration.ps1 / .cmd / .bat - 启动时自动检测并执行未应用迁移 - 从 appsettings.json 读取数据库配置
57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using Avalonia_API.Configuration;
|
||
using Avalonia_API.Extensions;
|
||
using Avalonia_Common.Infrastructure;
|
||
using Avalonia_EFCore.Database;
|
||
using Avalonia_Services.Core;
|
||
using Serilog;
|
||
|
||
// 初始化日志系统
|
||
Log.Logger = LoggingConfiguration.CreateDefaultLogger(logDir: "logs");
|
||
Log.Information("Avalonia-API 正在启动...");
|
||
|
||
try
|
||
{
|
||
var builder = WebApplication.CreateBuilder(args);
|
||
|
||
// 使用 Serilog 作为日志提供程序
|
||
builder.Host.UseSerilog();
|
||
|
||
// Add services to the container.
|
||
builder.Services.AddControllers();
|
||
builder.Services.AddOpenApi();
|
||
|
||
// 注册统一端点及业务服务(入口在 Avalonia-Services/Endpoints/AppEndpoints.cs)
|
||
builder.Services.AddUnifiedApiServices(builder.Configuration);
|
||
|
||
var app = builder.Build();
|
||
|
||
// 初始化数据库(自动迁移 + 种子数据)
|
||
app.Services.InitializeDatabase<AppDataContext>();
|
||
|
||
// 启动时打印所有接口
|
||
var endpoints = app.Services.GetRequiredService<ServiceEndpointCollection>();
|
||
EndpointPrinter.PrintEndpoints(endpoints, "Avalonia-API 接口列表");
|
||
|
||
// Configure the HTTP request pipeline.
|
||
if (app.Environment.IsDevelopment())
|
||
{
|
||
app.MapOpenApi();
|
||
}
|
||
|
||
app.UseHttpsRedirection();
|
||
app.UseAuthorization();
|
||
|
||
// 将统一端点映射到 ASP.NET Core 路由
|
||
app.MapUnifiedEndpoints(endpoints, app.Services);
|
||
|
||
app.Run();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Fatal(ex, "Avalonia-API 启动失败");
|
||
}
|
||
finally
|
||
{
|
||
Log.CloseAndFlush();
|
||
}
|