using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore;
///
/// SqlSugar Core扩展方法
///
public static class SqlSugarCoreExtensions
{
///
/// 添加数据库上下文
///
/// 数据库上下文类型
/// 服务集合
/// 服务生命周期
/// 服务集合
public static IServiceCollection AddYiDbContext(
this IServiceCollection services,
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
where TDbContext : class, ISqlSugarDbContextDependencies
{
services.Add(new ServiceDescriptor(
typeof(ISqlSugarDbContextDependencies),
typeof(TDbContext),
serviceLifetime));
return services;
}
///
/// 添加数据库上下文并配置选项
///
/// 数据库上下文类型
/// 服务集合
/// 配置选项委托
/// 服务集合
public static IServiceCollection AddYiDbContext(
this IServiceCollection services,
Action configureOptions)
where TDbContext : class, ISqlSugarDbContextDependencies
{
services.Configure(configureOptions);
services.AddYiDbContext();
return services;
}
}