2026-05-11 14:35:34 +08:00
|
|
|
|
using Avalonia_EFCore.Database;
|
|
|
|
|
|
using Avalonia_Services.Core;
|
|
|
|
|
|
using Avalonia_Services.Database;
|
|
|
|
|
|
using Avalonia_Services.Endpoints;
|
|
|
|
|
|
using Avalonia_Services.Services;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-04-23 17:25:31 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Avalonia_API.Configuration
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ServicesConfiguration
|
|
|
|
|
|
{
|
2026-05-11 14:35:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 注册统一端点及其依赖的服务(含数据库)。
|
|
|
|
|
|
/// 所有业务端点定义在 Avalonia-Services/Endpoints/AppEndpoints.cs。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static IServiceCollection AddUnifiedApiServices(this IServiceCollection services)
|
2026-04-23 17:25:31 +08:00
|
|
|
|
{
|
2026-05-11 14:35:34 +08:00
|
|
|
|
// ---- 数据库 ----
|
|
|
|
|
|
// 从 appsettings.json 读取 DatabaseConfiguration 节
|
|
|
|
|
|
// 注册默认数据库提供程序(SQLite / MySQL / PostgreSQL / SqlServer)
|
|
|
|
|
|
DatabaseProviderRegistry.RegisterDefaults();
|
|
|
|
|
|
|
|
|
|
|
|
// 注册 AppDataContext(共享数据上下文)
|
|
|
|
|
|
services.AddAppDatabase<AppDataContext>(DatabaseConfiguration.ForSQLite("app.db"));
|
|
|
|
|
|
|
|
|
|
|
|
// ---- 业务服务 ----
|
2026-04-23 17:25:31 +08:00
|
|
|
|
services.AddScoped<WeatherForecastService>();
|
2026-05-11 14:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
// ---- 统一端点 ----
|
|
|
|
|
|
var endpointBuilder = new ServiceEndpointBuilder();
|
|
|
|
|
|
AppEndpoints.Configure(endpointBuilder);
|
|
|
|
|
|
var endpoints = endpointBuilder.Build();
|
|
|
|
|
|
services.AddSingleton(endpoints);
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
2026-04-23 17:25:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|