namespace Elsa.Common.Multitenancy;
///
/// Base class for implementing a tenant resolution strategy.
///
public abstract class TenantResolverBase : ITenantResolver
{
Task ITenantResolver.ResolveAsync(TenantResolverContext context)
{
return ResolveAsync(context);
}
///
/// Implement this method to resolve the tenant.
///
protected virtual Task ResolveAsync(TenantResolverContext context)
{
return Task.FromResult(Resolve(context));
}
///
/// Implement this method to resolve the tenant.
///
protected virtual TenantResolverResult Resolve(TenantResolverContext context)
{
return Unresolved();
}
///
/// Creates a new instance of representing a resolved tenant.
///
protected TenantResolverResult Resolved(string tenantId) => new(tenantId);
///
/// Creates a new instance of representing an unresolved tenant.
///
protected TenantResolverResult Unresolved() => new(null);
///
/// Automatically resolves the tenant if the tenant ID is not null.
///
protected TenantResolverResult AutoResolve(string? tenantId) => tenantId == null ? Unresolved() : Resolved(tenantId);
}