using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TelegramPanel.Data.Repositories;
namespace TelegramPanel.Data;
///
/// Data层服务注册扩展
///
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddTelegramPanelData(this IServiceCollection services, string connectionString)
{
// 注册数据库上下文
services.AddDbContext(options =>
options.UseSqlite(connectionString, sqlite =>
{
// 避免 Include 多个集合导航时的“笛卡尔爆炸”与性能警告
sqlite.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
}));
// 注册所有Repository
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
return services;
}
}