重构项目结构,引入 Avalonia-Common、Avalonia-EFCore、Avalonia-Services,实现 API 与桌面端统一端点注册、过滤器、鉴权和标准响应格式。支持多数据库自动迁移与配置,集成 Serilog 日志系统。移除旧路由与控制器,提升接口一致性与可维护性。
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using Avalonia_EFCore.Database;
|
||
using Avalonia_Services.Core;
|
||
using Avalonia_Services.Database;
|
||
using Avalonia_Services.Endpoints;
|
||
using Avalonia_Services.Services;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
namespace Avalonia_API.Configuration
|
||
{
|
||
public static class ServicesConfiguration
|
||
{
|
||
/// <summary>
|
||
/// 注册统一端点及其依赖的服务(含数据库)。
|
||
/// 所有业务端点定义在 Avalonia-Services/Endpoints/AppEndpoints.cs。
|
||
/// </summary>
|
||
public static IServiceCollection AddUnifiedApiServices(this IServiceCollection services)
|
||
{
|
||
// ---- 数据库 ----
|
||
// 从 appsettings.json 读取 DatabaseConfiguration 节
|
||
// 注册默认数据库提供程序(SQLite / MySQL / PostgreSQL / SqlServer)
|
||
DatabaseProviderRegistry.RegisterDefaults();
|
||
|
||
// 注册 AppDataContext(共享数据上下文)
|
||
services.AddAppDatabase<AppDataContext>(DatabaseConfiguration.ForSQLite("app.db"));
|
||
|
||
// ---- 业务服务 ----
|
||
services.AddScoped<WeatherForecastService>();
|
||
|
||
// ---- 统一端点 ----
|
||
var endpointBuilder = new ServiceEndpointBuilder();
|
||
AppEndpoints.Configure(endpointBuilder);
|
||
var endpoints = endpointBuilder.Build();
|
||
services.AddSingleton(endpoints);
|
||
|
||
return services;
|
||
}
|
||
}
|
||
}
|