ow
This commit is contained in:
1 parent
fcbeba7287
commit
f2f5807372
33 files changed
+1399
-1444
No files matched your search
@@ -15,6 +15,15 @@ namespace CloudBuilder.Core.DatabaseAccessor
|
||||
{
|
||||
public class ApplicationService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 显式赋值的登录Id(登录流程/桌面端会主动赋值),为空时按当前请求的令牌解析
|
||||
/// </summary>
|
||||
private string? userId;
|
||||
|
||||
/// <summary>
|
||||
/// 显式赋值的语言,为空时按当前请求的报文头解析
|
||||
/// </summary>
|
||||
private string? locale;
|
||||
|
||||
public ApplicationService(
|
||||
CloudBuilderBuilder cloudBuilder,
|
||||
@@ -29,23 +38,47 @@ namespace CloudBuilder.Core.DatabaseAccessor
|
||||
this.ServiceProvider = serviceProvider;
|
||||
this.UnitOfWork = unitOfWork;
|
||||
this.HttpContext = httpContext;
|
||||
if (httpContext.HttpContext != null)
|
||||
{
|
||||
UserId = ClaimPolicy.GetClaimValue(HttpContext, ClaimPolicy.CLAINM_USERID);
|
||||
string key = ClaimPolicy.GetHeaderKeyValue(HttpContext, ClaimPolicy.HEADER_LOCALE);
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
Locale = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
public IHttpContextAccessor HttpContext { get; private set; }
|
||||
|
||||
public string UserId { get; set; }
|
||||
public string Locale { get; set; } = ClaimPolicy.CLAINM_LOCALE;
|
||||
/// <summary>
|
||||
/// 当前登录Id:取自当前请求的令牌,每次访问都重新解析
|
||||
/// (不能在构造函数中缓存,否则实例被长生命周期对象持有时会一直返回上一个登录用户)
|
||||
/// </summary>
|
||||
public string UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userId)) return userId!;
|
||||
if (HttpContext?.HttpContext == null) return string.Empty;
|
||||
return ClaimPolicy.GetClaimValue(HttpContext, ClaimPolicy.CLAINM_USERID);
|
||||
}
|
||||
set
|
||||
{
|
||||
userId = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前语言:取自当前请求的报文头,每次访问都重新解析
|
||||
/// </summary>
|
||||
public string Locale
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(locale)) return locale!;
|
||||
if (HttpContext?.HttpContext == null) return ClaimPolicy.CLAINM_LOCALE;
|
||||
string key = ClaimPolicy.GetHeaderKeyValue(HttpContext, ClaimPolicy.HEADER_LOCALE);
|
||||
return string.IsNullOrEmpty(key) ? ClaimPolicy.CLAINM_LOCALE : key;
|
||||
}
|
||||
set
|
||||
{
|
||||
locale = value;
|
||||
}
|
||||
}
|
||||
public IUnitOfWork UnitOfWork { get; set; }
|
||||
public CloudBuilderBuilder CloudBuilder { get; set; }
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
|
||||
Reference in new issue
Block a user