| | | 1 | | namespace Elsa.Common.Multitenancy; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Base class for implementing a tenant resolution strategy. |
| | | 5 | | /// </summary> |
| | | 6 | | public abstract class TenantResolverBase : ITenantResolver |
| | | 7 | | { |
| | | 8 | | Task<TenantResolverResult> ITenantResolver.ResolveAsync(TenantResolverContext context) |
| | | 9 | | { |
| | 0 | 10 | | return ResolveAsync(context); |
| | | 11 | | } |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Implement this method to resolve the tenant. |
| | | 15 | | /// </summary> |
| | | 16 | | protected virtual Task<TenantResolverResult> ResolveAsync(TenantResolverContext context) |
| | | 17 | | { |
| | 0 | 18 | | return Task.FromResult(Resolve(context)); |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Implement this method to resolve the tenant. |
| | | 23 | | /// </summary> |
| | | 24 | | protected virtual TenantResolverResult Resolve(TenantResolverContext context) |
| | | 25 | | { |
| | 0 | 26 | | return Unresolved(); |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Creates a new instance of <see cref="TenantResolverResult"/> representing a resolved tenant. |
| | | 31 | | /// </summary> |
| | 0 | 32 | | protected TenantResolverResult Resolved(string tenantId) => new(tenantId); |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Creates a new instance of <see cref="TenantResolverResult"/> representing an unresolved tenant. |
| | | 36 | | /// </summary> |
| | 0 | 37 | | protected TenantResolverResult Unresolved() => new(null); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Automatically resolves the tenant if the tenant ID is not null. |
| | | 41 | | /// </summary> |
| | 0 | 42 | | protected TenantResolverResult AutoResolve(string? tenantId) => tenantId == null ? Unresolved() : Resolved(tenantId) |
| | | 43 | | } |