P0 - 安全修复: - 移除硬编码 API Key,启动时校验必填环境变量 P1 - 高优先级: - Entity 拆分:Position.cs, Transaction.cs 独立文件 - Controller Facade 封装:IPortfolioFacade 减少依赖注入 P2 - 中优先级: - Repository 抽象:IPortfolioRepository, IMarketDataRepository - MarketDataService 拆分:组合模式整合 Tencent/Tiingo/OKX P3 - 低优先级: - DTO 命名规范:统一 PascalCase - 单元测试框架:xUnit + Moq + FluentAssertions
32 lines
930 B
C#
Executable File
32 lines
930 B
C#
Executable File
using AssetManager.Data.Repositories;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace AssetManager.Data;
|
|
|
|
public static class DatabaseExtensions
|
|
{
|
|
public static IServiceCollection AddDatabase(this IServiceCollection services)
|
|
{
|
|
services.AddScoped<ISqlSugarClient>(s =>
|
|
{
|
|
return SqlSugarConfig.GetSqlSugarClient();
|
|
});
|
|
|
|
services.AddScoped<DatabaseService>();
|
|
|
|
// Repository 层
|
|
services.AddScoped<IPortfolioRepository, PortfolioRepository>();
|
|
services.AddScoped<IMarketDataRepository, MarketDataRepository>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static void InitializeDatabase(this IServiceProvider serviceProvider)
|
|
{
|
|
using var scope = serviceProvider.CreateScope();
|
|
var dbService = scope.ServiceProvider.GetRequiredService<DatabaseService>();
|
|
dbService.InitializeDatabase();
|
|
}
|
|
}
|