using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本:4.0.30319.42000
* 机器名称:LAPTOP-E0N2L34V
* 命名空间:SlnMesnac.Extensions
* 唯一标识:bbb46406-e99d-4205-8046-ad954cf88315
*
* 创建者:WenJY
* 电子邮箱:wenjy@mesnac.com
* 创建时间:2024-04-12 17:31:43
* 版本:V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本:V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Extensions
{
public static class SqlsugarSetup
{
///
/// 注册SqlSugar
///
///
public static void AddSqlSugarSetup(this IServiceCollection services)
{
services.AddSingleton(x =>
{
var appConfig = x.GetService();
var connectConfigList = new List();
if (appConfig.sqlConfig != null)
{
foreach (var item in appConfig.sqlConfig)
{
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;
});
}
}
}