|
|
#region << 版 本 注 释 >>
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
* 版权所有 (c) 2025 WenJY 保留所有权利。
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
* 机器名称:Mr.Wen's MacBook Pro
|
|
|
* 命名空间:Sln.Imm.Daemon.Repository
|
|
|
* 唯一标识:E2ACD454-D380-4130-8B28-FB2A2BF58530
|
|
|
*
|
|
|
* 创建者:WenJY
|
|
|
* 电子邮箱:
|
|
|
* 创建时间:2025-09-05 11:22:32
|
|
|
* 版本:V1.0.0
|
|
|
* 描述:
|
|
|
*
|
|
|
*--------------------------------------------------------------------
|
|
|
* 修改人:
|
|
|
* 时间:
|
|
|
* 修改说明:
|
|
|
*
|
|
|
* 版本:V1.0.0
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Sln.Imm.Daemon.Config;
|
|
|
using SqlSugar;
|
|
|
|
|
|
namespace Sln.Imm.Daemon.Repository;
|
|
|
|
|
|
public static class SqlsugarSetup
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 注册SqlSugar
|
|
|
/// </summary>
|
|
|
/// <param name="services"></param>
|
|
|
public static void AddSqlSugarSetup(this IServiceCollection services)
|
|
|
{
|
|
|
services.AddSingleton<ISqlSugarClient>(x =>
|
|
|
{
|
|
|
var appConfig = x.GetService<AppConfig>();
|
|
|
|
|
|
var connectConfigList = new List<ConnectionConfig>();
|
|
|
if (appConfig.sqlConfig != null)
|
|
|
{
|
|
|
foreach (var item in appConfig.sqlConfig)
|
|
|
{
|
|
|
if (item.isFlag)
|
|
|
{
|
|
|
var config = new ConnectionConfig()
|
|
|
{
|
|
|
ConfigId = item.configId,
|
|
|
DbType = (DbType)item.dbType,
|
|
|
ConnectionString = item.connStr,
|
|
|
InitKeyType = InitKeyType.Attribute,
|
|
|
IsAutoCloseConnection = true,
|
|
|
};
|
|
|
connectConfigList.Add(config);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
SqlSugarScope Db =
|
|
|
new SqlSugarScope(connectConfigList, db => { db.Aop.OnLogExecuting = (sql, pars) => { }; });
|
|
|
|
|
|
return Db;
|
|
|
});
|
|
|
}
|
|
|
} |