| | | 1 | | namespace Elsa.Common.Multitenancy; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents the result of a tenant resolution. |
| | | 5 | | /// </summary> |
| | | 6 | | public record TenantResolverResult |
| | | 7 | | { |
| | | 8 | | private readonly bool _isResolved; |
| | | 9 | | |
| | 291 | 10 | | private TenantResolverResult(string? tenantId, bool isResolved) |
| | | 11 | | { |
| | 291 | 12 | | TenantId = tenantId; |
| | 291 | 13 | | _isResolved = isResolved; |
| | 291 | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// The normalized tenant ID. Returns null if unresolved. |
| | | 18 | | /// </summary> |
| | 291 | 19 | | public string? TenantId => _isResolved ? field.NormalizeTenantId() : null; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Creates a new instance of <see cref="TenantResolverResult"/> representing a resolved tenant. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="tenantId">The resolved tenant.</param> |
| | | 25 | | /// <returns>A new instance of <see cref="TenantResolverResult"/> representing a resolved tenant.</returns> |
| | 291 | 26 | | public static TenantResolverResult Resolved(string? tenantId) => new(tenantId, true); |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Creates a new instance of <see cref="TenantResolverResult"/> representing an unresolved tenant. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <returns>A new instance of <see cref="TenantResolverResult"/> representing an unresolved tenant.</returns> |
| | 0 | 32 | | public static TenantResolverResult Unresolved() => new(null, false); |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets a value indicating whether the tenant has been resolved. |
| | | 36 | | /// </summary> |
| | 291 | 37 | | public bool IsResolved => _isResolved; |
| | | 38 | | |
| | 291 | 39 | | public string ResolveTenantId() => TenantId ?? throw new InvalidOperationException("Tenant has not been resolved."); |
| | | 40 | | } |