ソースを参照

😁优化sqlsugar初始化

zuohuaijun 2 年 前
コミット
db326deb83

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

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

+ 3 - 3
Admin.NET/Admin.NET.Core/Service/APIJSON/APIJSONService.cs

@@ -91,7 +91,7 @@ public class APIJSONService : IDynamicApiController, ITransient
     /// </summary>
     /// <param name="tables">表对象或数组,若没有传Id则后端生成Id</param>
     /// <returns></returns>
-    [HttpPost("post")]
+    [HttpPost("add")]
     [UnitOfWork]
     public JObject Add([FromBody] JObject tables)
     {
@@ -133,7 +133,7 @@ public class APIJSONService : IDynamicApiController, ITransient
     /// </summary>
     /// <param name="tables">支持多表、多Id批量更新</param>
     /// <returns></returns>
-    [HttpPost("post")]
+    [HttpPost("update")]
     [UnitOfWork]
     public JObject Edit([FromBody] JObject tables)
     {
@@ -153,7 +153,7 @@ public class APIJSONService : IDynamicApiController, ITransient
     /// </summary>
     /// <param name="tables"></param>
     /// <returns></returns>
-    [HttpPost("post")]
+    [HttpPost("delete")]
     [UnitOfWork]
     public JObject Delete([FromBody] JObject tables)
     {

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

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

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

@@ -39,9 +39,9 @@ public static class SqlSugarSetup
                 SetDbDiffLog(dbProvider, config);
             });
         });
-        SqlSugarConst.ITenant = sqlSugar.AsTenant();
 
         services.AddSingleton<ISqlSugarClient>(sqlSugar); // 单例注册
+        services.AddSingleton(sqlSugar.AsTenant()); // 多租户单例注册
         services.AddScoped(typeof(SqlSugarRepository<>)); // 仓储注册
         services.AddUnitOfWork<SqlSugarUnitOfWork>(); // 事务与工作单元注册