TenantResolveHelper.cs
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using FoodLabeling.Domain.Shared.MultiTenancy;
using Volo.Abp;
using Volo.Abp.MultiTenancy;
namespace FoodLabeling.Th.Application.MultiTenancy;
/// <summary>
/// 平台主库解析租户配置(供泰额登录/Web 登录共用)
/// </summary>
public static class TenantResolveHelper
{
public static async Task<TenantConfiguration> ResolveTenantAsync(
ITenantStore tenantStore,
ICurrentTenant currentTenant,
Guid tenantId)
{
if (tenantId == Guid.Empty)
{
throw new UserFriendlyException("租户 Id 不能为空");
}
TenantConfiguration? config;
using (currentTenant.Change(null))
{
config = await tenantStore.FindAsync(tenantId);
}
if (config is null)
{
throw new UserFriendlyException("租户不存在或已停用");
}
if (string.IsNullOrWhiteSpace(config.ConnectionStrings?.Default))
{
throw new UserFriendlyException("租户未配置业务库连接串");
}
return config;
}
public static bool IsSeparateDatabaseMode(string? mode) =>
string.Equals(
mode?.Trim(),
FoodLabelingMultiTenancyConsts.SeparateDatabaseMode,
StringComparison.OrdinalIgnoreCase);
}