using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Gpulse.WCT.DataAnalyzer.Core.Infrastructure.LocalData;
using Gpulse.WCT.DataAnalyzer.Core.Application.Parsing;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Core.Infrastructure.Extensions;
///
/// 服务注册扩展
///
public static class ServiceCollectionExtensions
{
///
/// 注册数据库服务
///
public static IServiceCollection AddDatabaseServices(
this IServiceCollection services,
IConfiguration configuration)
{
// 注册 DbContext 工厂
services.AddScoped();
// 注册 DbContext(通过工厂创建)
services.AddScoped(sp =>
{
var factory = sp.GetRequiredService();
return factory.CreateDbContext();
});
services.AddScoped();
// 注册正式发布数据库上下文(与本地解析数据库完全独立)
services.AddScoped(sp =>
{
var factory = sp.GetRequiredService();
return factory.CreateDbContext();
});
return services;
}
///
/// 注册应用服务
///
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
// Parsers
services.AddScoped();
services.AddScoped();
services.AddSingleton();
// Services
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
return services;
}
}