perf: 改用sqlsugar db上下文对象
This commit is contained in:
@@ -24,12 +24,14 @@ namespace Yi.Framework.Core.Sqlsugar.Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SqlsugarExtensions
|
public static class SqlsugarExtensions
|
||||||
{
|
{
|
||||||
|
//使用上下文对象
|
||||||
public static void AddDbSqlsugarContextServer(this IServiceCollection services)
|
public static void AddDbSqlsugarContextServer(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient(x => x.GetRequiredService<SqlSugarDbContext>().SqlSugarClient);
|
services.AddSingleton<ISqlSugarClient>(x => x.GetRequiredService<SqlSugarDbContext>().SqlSugarClient);
|
||||||
services.AddTransient<SqlSugarDbContext>();
|
services.AddSingleton<SqlSugarDbContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//直接使用sqlsugar
|
||||||
public static void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient>? action = null)
|
public static void AddSqlsugarServer(this IServiceCollection services, Action<SqlSugarClient>? action = null)
|
||||||
{
|
{
|
||||||
var dbConnOptions = Appsettings.app<DbConnOptions>("DbConnOptions");
|
var dbConnOptions = Appsettings.app<DbConnOptions>("DbConnOptions");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Yi.Framework.Core.Sqlsugar
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// SqlSugar 客户端
|
/// SqlSugar 客户端
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISqlSugarClient SqlSugarClient { get; set; }
|
public ISqlSugarClient SqlSugarClient { get; set; }
|
||||||
|
|
||||||
protected ICurrentUser _currentUser;
|
protected ICurrentUser _currentUser;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ namespace Yi.Framework.Core.Sqlsugar
|
|||||||
{
|
{
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_options= options;
|
_options = options;
|
||||||
var dbConnOptions = options.Value;
|
var dbConnOptions = options.Value;
|
||||||
#region 组装options
|
#region 组装options
|
||||||
if (dbConnOptions.DbType is null)
|
if (dbConnOptions.DbType is null)
|
||||||
@@ -57,7 +57,7 @@ namespace Yi.Framework.Core.Sqlsugar
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
ISqlSugarClient sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
SqlSugarClient = new SqlSugarScope(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
//准备添加分表分库
|
//准备添加分表分库
|
||||||
DbType = dbConnOptions.DbType ?? DbType.Sqlite,
|
DbType = dbConnOptions.DbType ?? DbType.Sqlite,
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ namespace Yi.Framework.Core.Sqlsugar
|
|||||||
services.Replace(new ServiceDescriptor(typeof(IUnitOfWorkManager), typeof(SqlsugarUnitOfWorkManager), ServiceLifetime.Singleton));
|
services.Replace(new ServiceDescriptor(typeof(IUnitOfWorkManager), typeof(SqlsugarUnitOfWorkManager), ServiceLifetime.Singleton));
|
||||||
services.Replace(new ServiceDescriptor(typeof(IDataFilter), typeof(SqlsugarDataFilter), ServiceLifetime.Scoped));
|
services.Replace(new ServiceDescriptor(typeof(IDataFilter), typeof(SqlsugarDataFilter), ServiceLifetime.Scoped));
|
||||||
services.Configure<DbConnOptions>(Appsettings.appConfiguration("DbConnOptions"));
|
services.Configure<DbConnOptions>(Appsettings.appConfiguration("DbConnOptions"));
|
||||||
services.AddSqlsugarServer();
|
|
||||||
|
//使用db上下文
|
||||||
|
services.AddDbSqlsugarContextServer();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user