diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbContext.cs
index 8fc6afa5..cd4f9dce 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbContext.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbContext.cs
@@ -10,14 +10,14 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
{
public interface ISqlSugarDbContext
{
- // IAbpLazyServiceProvider LazyServiceProvider { get; set; }
+ ///
+ /// SqlSugarDb
+ ///
ISqlSugarClient SqlSugarClient { get; }
- DbConnOptions Options { get; }
///
/// 数据库备份
///
void BackupDataBase();
- void SetSqlSugarClient(ISqlSugarClient sqlSugarClient);
}
}
diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/ISqlSugarDbContextDependencies.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/ISqlSugarDbContextDependencies.cs
index 37d75599..f3826abe 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/ISqlSugarDbContextDependencies.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/ISqlSugarDbContextDependencies.cs
@@ -5,7 +5,7 @@ namespace Yi.Framework.SqlSugarCore;
public interface ISqlSugarDbContextDependencies
{
- void OnSqlSugarClientConfig(ISqlSugarClient client);
+ void OnSqlSugarClientConfig(ISqlSugarClient client);
void DataExecuted(object obj, DataAfterModel dataAfterModel);
void DataExecuting(object obj, DataFilterModel dataAfterModel);
diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContextFactory.cs
similarity index 82%
rename from Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs
rename to Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContextFactory.cs
index 247aad4a..8e5cc37e 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContextFactory.cs
@@ -1,16 +1,9 @@
-using System.Collections;
-using System.Reflection;
-using System.Text;
+using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SqlSugar;
-using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
-using Volo.Abp.Domain.Entities;
-using Volo.Abp.Domain.Entities.Events;
-using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Users;
using Yi.Framework.SqlSugarCore.Abstractions;
@@ -18,7 +11,7 @@ using Check = Volo.Abp.Check;
namespace Yi.Framework.SqlSugarCore
{
- public class SqlSugarDbContext : ISqlSugarDbContext
+ public class SqlSugarDbContextFactory : ISqlSugarDbContext
{
///
/// SqlSugar 客户端
@@ -28,42 +21,30 @@ namespace Yi.Framework.SqlSugarCore
protected ICurrentUser CurrentUser => LazyServiceProvider.GetRequiredService();
private IAbpLazyServiceProvider LazyServiceProvider { get; }
- private IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetRequiredService();
- private ILoggerFactory Logger => LazyServiceProvider.LazyGetRequiredService();
private ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService();
protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService();
- protected virtual bool IsMultiTenantFilterEnabled => DataFilter?.IsEnabled() ?? false;
-
- protected virtual bool IsSoftDeleteFilterEnabled => DataFilter?.IsEnabled() ?? false;
-
- private IEntityChangeEventHelper EntityChangeEventHelper =>
- LazyServiceProvider.LazyGetService(NullEntityChangeEventHelper.Instance);
public DbConnOptions Options => LazyServiceProvider.LazyGetRequiredService>().Value;
private ISerializeService SerializeService => LazyServiceProvider.LazyGetRequiredService();
private IEnumerable SqlSugarDbContextDependencies=>LazyServiceProvider.LazyGetRequiredService>();
- public void SetSqlSugarClient(ISqlSugarClient sqlSugarClient)
- {
- SqlSugarClient = sqlSugarClient;
- }
-
- public SqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider)
+
+ public SqlSugarDbContextFactory(IAbpLazyServiceProvider lazyServiceProvider)
{
LazyServiceProvider = lazyServiceProvider;
- var connectionCreators = LazyServiceProvider.LazyGetRequiredService();
-
+
+ //获取连接配置
var connectionConfig = BuildConnectionConfig(action: options =>
{
options.ConnectionString = GetCurrentConnectionString();
options.DbType = GetCurrentDbType();
});
SqlSugarClient = new SqlSugarClient(connectionConfig);
+
//替换默认序列化器
SqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SerializeService = SerializeService;
-
- //最后一步,将全程序dbcontext汇总
+
// Aop及多租户连接字符串和类型,需要单独设置
SetDbAop(SqlSugarClient);
}
@@ -72,14 +53,32 @@ namespace Yi.Framework.SqlSugarCore
/// 构建Aop-sqlsugaraop在多租户模式中,需单独设置
///
///
- public void SetDbAop(ISqlSugarClient sqlSugarClient)
+ protected virtual void SetDbAop(ISqlSugarClient sqlSugarClient)
{
//将所有,ISqlSugarDbContextDependencies进行累加
- sqlSugarClient.Aop.OnLogExecuting = this.OnLogExecuting;
- sqlSugarClient.Aop.OnLogExecuted = this.OnLogExecuted;
- sqlSugarClient.Aop.DataExecuting = this.DataExecuting;
- sqlSugarClient.Aop.DataExecuted = this.DataExecuted;
- OnSqlSugarClientConfig(currentDb);
+ Action onLogExecuting=null;
+ Action onLogExecuted=null;
+ Action