From 5af11cc200dd5ebe474b9c0475883b0e6d1e3759 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 三月 2026 10:00:49 +0800
Subject: [PATCH] 重构整个项目:改进代码质量和架构
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/App.cs | 26 +++++++++++++-------------
1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/App.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/App.cs
index f15e9c1..739fec3 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/App.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/App.cs
@@ -49,7 +49,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;
@@ -63,7 +63,7 @@
/// <summary>
/// 鑾峰彇璇锋眰涓婁笅鏂�
/// </summary>
- public static HttpContext HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext;
+ public static HttpContext? HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext;
public static IUser User => GetService<IUser>();
@@ -108,10 +108,10 @@
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;
- return test;
+ object? service = App.GetService(typeof(TService), null, mustBuild);
+ return service as TService;
}
/// <summary>鑾峰彇璇锋眰鐢熷瓨鍛ㄦ湡鐨勬湇鍔�</summary>
@@ -119,7 +119,7 @@
/// <param name="serviceProvider"></param>
/// <param name="mustBuild"></param>
/// <returns></returns>
- public static TService GetService<TService>(IServiceProvider serviceProvider, bool mustBuild = true)
+ public static TService? GetService<TService>(IServiceProvider? serviceProvider, bool mustBuild = true)
where TService : class => (serviceProvider ?? App.GetServiceProvider(typeof(TService), mustBuild, false))?.GetService<TService>();
/// <summary>鑾峰彇璇锋眰鐢熷瓨鍛ㄦ湡鐨勬湇鍔�</summary>
@@ -127,10 +127,10 @@
/// <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)
{
IServiceProvider? obj2 = (serviceProvider ?? App.GetServiceProvider(type, mustBuild, false));
- object obj = obj2?.GetService(type);
+ object? obj = obj2?.GetService(type);
return obj;
}
@@ -177,7 +177,7 @@
/// <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? serviceProvider = null) where TOptions : class, new()
{
IOptions<TOptions> service = App.GetService<IOptions<TOptions>>(serviceProvider ?? App.RootServices, false);
return service?.Value;
@@ -187,10 +187,10 @@
/// <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 =
+ IOptionsMonitor<TOptions>? service =
App.GetService<IOptionsMonitor<TOptions>>(serviceProvider ?? App.RootServices, false);
return service?.CurrentValue;
}
@@ -199,10 +199,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 = App.GetService<IOptionsSnapshot<TOptions>>(serviceProvider, false);
return service?.Value;
}
--
Gitblit v1.9.3