Преглед изворни кода

修改作用域改成异步模式、调整sqlsugar注册顺序

zuohuaijun пре 3 година
родитељ
комит
9b38c33aa4

+ 1 - 1
Admin.NET/Admin.NET.Core/Job/LogJob.cs

@@ -13,7 +13,7 @@ public class LogJob : ISpareTimeWorker
     [SpareTime("@midnight", "清理日志", Description = "每天午夜运行一次", DoOnce = false, StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
     public void ClearLogJob(SpareTimer timer, long count)
     {
-        Scoped.Create(async (_, scope) =>
+        Scoped.CreateAsync(async (_, scope) =>
         {
             var services = scope.ServiceProvider;
             var db = services.GetService<ISqlSugarClient>();

+ 8 - 8
Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs

@@ -11,14 +11,14 @@ public class OnlineUserJob : ISpareTimeWorker
     [SpareTime(1000, "清空在线用户", Description = "服务启动时运行", DoOnce = true, StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
     public void ClearOnlineUser(SpareTimer timer, long count)
     {
-        //Scoped.Create(async (_, scope) =>
-        //{
-        //    var services = scope.ServiceProvider;
-        //    var rep = services.GetService<SqlSugarRepository<SysOnlineUser>>();
-        //    await rep.AsDeleteable().ExecuteCommandAsync();
+        Scoped.CreateAsync(async (_, scope) =>
+        {
+            var services = scope.ServiceProvider;
+            var rep = services.GetService<SqlSugarRepository<SysOnlineUser>>();
+            await rep.AsDeleteable().ExecuteCommandAsync();
 
-        //    Console.ForegroundColor = ConsoleColor.Blue;
-        //    Console.WriteLine("【" + DateTime.Now + "——清空在线用户】\r\n服务重启触发清空在线用户");
-        //});
+            Console.ForegroundColor = ConsoleColor.Blue;
+            Console.WriteLine("【" + DateTime.Now + "——清空在线用户】\r\n服务重启触发清空在线用户");
+        });
     }
 }

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

@@ -11,7 +11,6 @@ public static class SqlSugarSetup
     public static void AddSqlSugar(this IServiceCollection services)
     {
         var dbOptions = App.GetOptions<DbConnectionOptions>();
-        var sqlSugarCache = new SqlSugarCache();
         var configureExternalServices = new ConfigureExternalServices
         {
             EntityService = (type, column) => // 修改列可空-1、带?问号 2、String类型若没有Required
@@ -20,7 +19,7 @@ public static class SqlSugarSetup
                     || (type.PropertyType == typeof(string) && type.GetCustomAttribute<RequiredAttribute>() == null))
                     column.IsNullable = true;
             },
-            DataInfoCacheService = sqlSugarCache,
+            DataInfoCacheService = new SqlSugarCache(),
         };
         dbOptions.ConnectionConfigs.ForEach(config =>
         {

+ 2 - 3
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -25,6 +25,8 @@ public class Startup : AppStartup
     {
         // 配置选项
         services.AddProjectOptions();
+        // SqlSugar
+        services.AddSqlSugar();
         // JWT
         services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
         // 允许跨域
@@ -54,9 +56,6 @@ public class Startup : AppStartup
         // 缓存注册
         services.AddCache();
 
-        // SqlSugar
-        services.AddSqlSugar();
-
         // 第三方授权登录
         services.AddAuthentication()
             .AddWeixin(options =>