mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-01-08 17:34:33 +08:00
⚠️feat: SqlSugar自动识别所有连接字符串
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
/// </summary>
|
||||
public static class Define
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认租户ID
|
||||
/// </summary>
|
||||
public const string DEFAULT_TENANT_ID = "OpenAuthDBContext";
|
||||
|
||||
//Relevance关联KEY
|
||||
/// <summary>
|
||||
/// 用户角色关联KEY
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Infrastructure.Extensions.AutofacManager
|
||||
public static TService GetService<TService>() where TService:class
|
||||
{
|
||||
Type typeParameterType = typeof(TService);
|
||||
return (TService)_provider.GetService(typeParameterType);
|
||||
return (TService)_provider?.GetService(typeParameterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ namespace Infrastructure.Utilities
|
||||
{
|
||||
public static class HttpContextUtil
|
||||
{
|
||||
private static IHttpContextAccessor _accessor=AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||
// 不要在静态初始化时获取IHttpContextAccessor,而是在需要时获取
|
||||
private static IHttpContextAccessor _accessor => AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||
|
||||
public static Microsoft.AspNetCore.Http.HttpContext Current => _accessor.HttpContext;
|
||||
public static Microsoft.AspNetCore.Http.HttpContext Current => _accessor?.HttpContext;
|
||||
|
||||
/// <summary>
|
||||
/// 获取租户ID
|
||||
@@ -15,7 +16,7 @@ namespace Infrastructure.Utilities
|
||||
/// <returns></returns>
|
||||
public static string GetTenantId(this IHttpContextAccessor accessor)
|
||||
{
|
||||
string tenantId = "OpenAuthDBContext";
|
||||
string tenantId = Define.DEFAULT_TENANT_ID;
|
||||
|
||||
if (accessor != null && accessor.HttpContext != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user