zuohuaijun 2 лет назад
Родитель
Сommit
c3d27ed213

+ 5 - 0
Admin.NET/Admin.NET.Core/Const/SqlSugarConst.cs

@@ -23,4 +23,9 @@ public class SqlSugarConst
     /// 默认表主键
     /// </summary>
     public const string PrimaryKey = "Id";
+
+    /// <summary>
+    /// 仓储对象
+    /// </summary>
+    public static ITenant ITenant { get; set; }
 }

+ 2 - 2
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs

@@ -10,11 +10,11 @@ namespace Admin.NET.Core;
 /// <typeparam name="T"></typeparam>
 public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
 {
-    protected ITenant iTenant = null;
+    protected ITenant iTenant;
 
     public SqlSugarRepository()
     {
-        iTenant = App.GetRequiredService<ISqlSugarClient>().AsTenant();
+        iTenant = SqlSugarConst.ITenant;
         base.Context = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);
 
         // 若实体贴有多库特性,则返回指定库连接

+ 1 - 0
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -39,6 +39,7 @@ public static class SqlSugarSetup
                 SetDbDiffLog(dbProvider, config);
             });
         });
+        SqlSugarConst.ITenant = sqlSugar.AsTenant();
 
         services.AddSingleton<ISqlSugarClient>(sqlSugar); // 单例注册
         services.AddScoped(typeof(SqlSugarRepository<>)); // 仓储注册