You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB
C#

2 weeks ago
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
2 weeks ago
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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
{
private static string GetCurrentProjectPath
{
get
{
return Environment.CurrentDirectory.Replace(@"\bin\Debug", "");//获取具体路径
}
}
2 weeks ago
/// <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)
{
var config = new ConnectionConfig()
{
ConfigId = item.configId,
DbType = (DbType)item.dbType,
ConnectionString = @"DataSource=" + GetCurrentProjectPath + @"\DataBase\SqlSugar4xTest.sqlite",
2 weeks ago
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
};
connectConfigList.Add(config);
}
}
SqlSugarScope Db = new SqlSugarScope(connectConfigList, db =>
{
db.Aop.OnLogExecuting = (sql, pars) => { };
});
return Db;
});
}
}
}