|
|
|
@ -2,6 +2,8 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Pages.Abp.MultiTenancy.ClientProxies; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
@ -13,6 +15,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client; |
|
|
|
|
|
|
|
public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
{ |
|
|
|
public ILogger<MvcRemoteTenantStore> Logger { get; set; } |
|
|
|
|
|
|
|
protected AbpTenantClientProxy TenantAppService { get; } |
|
|
|
protected IHttpContextAccessor HttpContextAccessor { get; } |
|
|
|
protected IDistributedCache<TenantConfigurationCacheItem> Cache { get; } |
|
|
|
@ -24,6 +28,8 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
IDistributedCache<TenantConfigurationCacheItem> cache, |
|
|
|
IOptions<AbpAspNetCoreMvcClientCacheOptions> options) |
|
|
|
{ |
|
|
|
Logger = NullLogger<MvcRemoteTenantStore>.Instance; |
|
|
|
|
|
|
|
TenantAppService = tenantAppService; |
|
|
|
HttpContextAccessor = httpContextAccessor; |
|
|
|
Cache = cache; |
|
|
|
@ -45,6 +51,11 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
{ |
|
|
|
var tenant = await TenantAppService.FindTenantByNameAsync(normalizedName); |
|
|
|
tenantConfiguration = await Cache.GetAsync(cacheKey); |
|
|
|
if (tenant.Success && tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " + |
|
|
|
"Ensure all applications use the same distributed cache and the same cache key prefix"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null) |
|
|
|
@ -68,8 +79,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
var tenantConfiguration = await Cache.GetAsync(cacheKey); |
|
|
|
if (tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
await TenantAppService.FindTenantByIdAsync(id); |
|
|
|
var tenant = await TenantAppService.FindTenantByIdAsync(id); |
|
|
|
tenantConfiguration = await Cache.GetAsync(cacheKey); |
|
|
|
if (tenant.Success && tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " + |
|
|
|
"Ensure all applications use the same distributed cache and the same cache key prefix"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null) |
|
|
|
@ -98,8 +114,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
var tenantConfiguration = Cache.Get(cacheKey); |
|
|
|
if (tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName)); |
|
|
|
var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName)); |
|
|
|
tenantConfiguration = Cache.Get(cacheKey); |
|
|
|
if (tenant.Success && tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " + |
|
|
|
"Ensure all applications use the same distributed cache and the same cache key prefix"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null) |
|
|
|
@ -123,8 +144,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency |
|
|
|
var tenantConfiguration = Cache.Get(cacheKey); |
|
|
|
if (tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id)); |
|
|
|
var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id)); |
|
|
|
tenantConfiguration = Cache.Get(cacheKey); |
|
|
|
if (tenant.Success && tenantConfiguration?.Value == null) |
|
|
|
{ |
|
|
|
Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " + |
|
|
|
"Ensure all applications use the same distributed cache and the same cache key prefix"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null) |
|
|
|
|