| | | 1 | | namespace Elsa.Common.Multitenancy; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents the context for resolving a tenant in a tenant resolution strategy pipeline. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <remarks> |
| | | 7 | | /// This class provides the necessary information for resolving a tenant, including a cancellation token |
| | | 8 | | /// to allow for cancelling the resolution process. |
| | | 9 | | /// </remarks> |
| | | 10 | | public class TenantResolverContext |
| | | 11 | | { |
| | | 12 | | private readonly IDictionary<string, Tenant> _tenantsDictionary; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="TenantResolverContext"/> class. |
| | | 16 | | /// </summary> |
| | 0 | 17 | | public TenantResolverContext(IDictionary<string, Tenant> tenants, CancellationToken cancellationToken) |
| | | 18 | | { |
| | 0 | 19 | | CancellationToken = cancellationToken; |
| | 0 | 20 | | _tenantsDictionary = tenants; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets the cancellation token. |
| | | 25 | | /// </summary> |
| | 0 | 26 | | public CancellationToken CancellationToken { get; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Finds a tenant based on the provided tenant ID. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="tenantId">The tenant ID.</param> |
| | | 32 | | /// <returns>The found tenant or null if no tenant with the provided ID exists.</returns> |
| | | 33 | | public Tenant? FindTenant(string tenantId) |
| | | 34 | | { |
| | 0 | 35 | | return _tenantsDictionary.TryGetValue(tenantId, out var tenant) ? tenant : null; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Finds a tenant based on the provided predicate. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <param name="predicate">The predicate used to filter the tenants.</param> |
| | | 42 | | /// <returns>The found tenant or null if no tenant satisfies the predicate.</returns> |
| | | 43 | | public Tenant? FindTenant(Func<Tenant, bool> predicate) |
| | | 44 | | { |
| | 0 | 45 | | return _tenantsDictionary.Values.FirstOrDefault(predicate); |
| | | 46 | | } |
| | | 47 | | } |