From 2aef482fa7431fb47eef94081ff23ec220f89820 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 24 一月 2025 09:10:31 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs
index 65be4ce..e6d530c 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs
@@ -34,6 +34,11 @@
             set => _isRun = IsBuild = value;
         }
 
+        /// <summary>
+        /// 鏈夋晥鏈�
+        /// </summary>
+        public static DateTime? ExpDateTime = null;
+
         /// <summary>搴旂敤鏈夋晥绋嬪簭闆�</summary>
         public static readonly IEnumerable<Assembly> Assemblies = RuntimeExtension.GetAllAssemblies();
 
@@ -41,7 +46,7 @@
         public static readonly IEnumerable<Type> EffectiveTypes;
 
         /// <summary>浼樺厛浣跨敤App.GetService()鎵嬪姩鑾峰彇鏈嶅姟</summary>
-        public static IServiceProvider RootServices => IsRun || IsBuild ? InternalApp.RootServices : null;
+        public static IServiceProvider? RootServices => IsRun || IsBuild ? InternalApp.RootServices : null;
 
         /// <summary>鑾峰彇Web涓绘満鐜锛屽锛屾槸鍚︽槸寮�鍙戠幆澧冿紝鐢熶骇鐜绛�</summary>
         public static IWebHostEnvironment WebHostEnvironment => InternalApp.WebHostEnvironment;
@@ -55,9 +60,9 @@
         /// <summary>
         /// 鑾峰彇璇锋眰涓婁笅鏂�
         /// </summary>
-        public static HttpContext HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext;
+        public static HttpContext? HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext;
 
-        public static IUser User => GetService<IUser>();
+        public static IUser? User => GetService<IUser>();
 
         #region Service
 
@@ -66,15 +71,15 @@
         /// <param name="mustBuild"></param>
         /// <param name="throwException"></param>
         /// <returns></returns>
-        public static IServiceProvider GetServiceProvider(Type serviceType, bool mustBuild = false, bool throwException = true)
+        public static IServiceProvider? GetServiceProvider(Type serviceType, bool mustBuild = false, bool throwException = true)
         {
-            if (App.HostEnvironment == null || App.RootServices != null &&
+            if (HostEnvironment == null || RootServices != null &&
                 InternalApp.InternalServices
                     .Where((u =>
                         u.ServiceType ==
                         (serviceType.IsGenericType ? serviceType.GetGenericTypeDefinition() : serviceType)))
                     .Any((u => u.Lifetime == ServiceLifetime.Singleton)))
-                return App.RootServices;
+                return RootServices;
 
             //鑾峰彇璇锋眰鐢熷瓨鍛ㄦ湡鐨勬湇鍔�
             if (HttpContext?.RequestServices != null)
@@ -100,9 +105,9 @@
             return serviceProvider;
         }
 
-        public static TService GetService<TService>(bool mustBuild = true) where TService : class
+        public static TService? GetService<TService>(bool mustBuild = true) where TService : class
         {
-            TService test = GetService(typeof(TService), null, mustBuild) as TService;
+            TService? test = GetService(typeof(TService), null, mustBuild) as TService;
             return test;
         }
 
@@ -111,17 +116,17 @@
         /// <param name="serviceProvider"></param>
         /// <param name="mustBuild"></param>
         /// <returns></returns>
-        public static TService GetService<TService>(IServiceProvider serviceProvider, bool mustBuild = true)
-            where TService : class => (serviceProvider ?? App.GetServiceProvider(typeof(TService), mustBuild, false))?.GetService<TService>();
+        public static TService? GetService<TService>(IServiceProvider? serviceProvider, bool mustBuild = true)
+            where TService : class => (serviceProvider ?? GetServiceProvider(typeof(TService), mustBuild, false))?.GetService<TService>();
 
         /// <summary>鑾峰彇璇锋眰鐢熷瓨鍛ㄦ湡鐨勬湇鍔�</summary>
         /// <param name="type"></param>
         /// <param name="serviceProvider"></param>
         /// <param name="mustBuild"></param>
         /// <returns></returns>
-        public static object GetService(Type type, IServiceProvider serviceProvider = null, bool mustBuild = true)
+        public static object? GetService(Type type, IServiceProvider? serviceProvider = null, bool mustBuild = true)
         {
-            object obj = (serviceProvider ?? GetServiceProvider(type, mustBuild, false))?.GetService(type);
+            object? obj = (serviceProvider ?? GetServiceProvider(type, mustBuild, false))?.GetService(type);
             return obj;
         }
 
@@ -158,7 +163,7 @@
         public static TOptions GetConfig<TOptions>()
             where TOptions : class, IConfigurableOptions
         {
-            TOptions instance = App.Configuration
+            TOptions instance = Configuration
                 .GetSection(ConfigurableOptions.GetConfigurationPath(typeof(TOptions)))
                 .Get<TOptions>();
             return instance;
@@ -168,9 +173,9 @@
         /// <typeparam name="TOptions">寮虹被鍨嬮�夐」绫�</typeparam>
         /// <param name="serviceProvider"></param>
         /// <returns>TOptions</returns>
-        public static TOptions GetOptions<TOptions>(IServiceProvider serviceProvider = null) where TOptions : class, new()
+        public static TOptions? GetOptions<TOptions>(IServiceProvider? rootServices, IServiceProvider serviceProvider = null) where TOptions : class, new()
         {
-            IOptions<TOptions> service = App.GetService<IOptions<TOptions>>(serviceProvider ?? App.RootServices, false);
+            IOptions<TOptions>? service = GetService<IOptions<TOptions>>(serviceProvider ?? rootServices, false);
             return service?.Value;
         }
 
@@ -178,11 +183,11 @@
         /// <typeparam name="TOptions">寮虹被鍨嬮�夐」绫�</typeparam>
         /// <param name="serviceProvider"></param>
         /// <returns>TOptions</returns>
-        public static TOptions GetOptionsMonitor<TOptions>(IServiceProvider serviceProvider = null)
+        public static TOptions? GetOptionsMonitor<TOptions>(IServiceProvider serviceProvider = null)
             where TOptions : class, new()
         {
-            IOptionsMonitor<TOptions> service =
-                App.GetService<IOptionsMonitor<TOptions>>(serviceProvider ?? App.RootServices, false);
+            IOptionsMonitor<TOptions>? service =
+                GetService<IOptionsMonitor<TOptions>>(serviceProvider ?? RootServices, false);
             return service?.CurrentValue;
         }
 
@@ -190,10 +195,10 @@
         /// <typeparam name="TOptions">寮虹被鍨嬮�夐」绫�</typeparam>
         /// <param name="serviceProvider"></param>
         /// <returns>TOptions</returns>
-        public static TOptions GetOptionsSnapshot<TOptions>(IServiceProvider serviceProvider = null)
+        public static TOptions? GetOptionsSnapshot<TOptions>(IServiceProvider serviceProvider = null)
             where TOptions : class, new()
         {
-            IOptionsSnapshot<TOptions> service = App.GetService<IOptionsSnapshot<TOptions>>(serviceProvider, false);
+            IOptionsSnapshot<TOptions>? service = GetService<IOptionsSnapshot<TOptions>>(serviceProvider, false);
             return service?.Value;
         }
 

--
Gitblit v1.9.3