From 17e4c7e3e7b3ef60d9da6de3b2a39a14a53c38a0 Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期三, 12 三月 2025 14:11:33 +0800 Subject: [PATCH] 1 --- WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs | 47 ++++++++++++++++++++++++++--------------------- 1 files changed, 26 insertions(+), 21 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/App.cs index 6cf3e41..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,21 +71,21 @@ /// <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) return HttpContext.RequestServices; - if (App.RootServices != null) + if (RootServices != null) { IServiceScope scope = RootServices.CreateScope(); return scope.ServiceProvider; @@ -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 = App.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 ?? App.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