ITenantInvalidationHandler<TKey> interface
Namespace: Tenantry · Package: Tenantry.Core · API reference
Clears data kept per tenant when the tenant changes. Every registered handler runs on ITenantInvalidator<TKey> invalidation, with or without CacheTenants. Tenantry.Caching, IsolateOutputCache() and Tenantry.Options register their own.
Register a handler as a singleton, once, with TryAddEnumerable. When the application also injects the handler to read what it keeps, register it once and forward the handler registration to that instance:
services.AddSingleton<PriceListCache>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITenantInvalidationHandler<Guid>, PriceListCache>(
sp => sp.GetRequiredService<PriceListCache>()));The handlers are resolved the first time a tenant is invalidated, so a handler may depend on ITenantInvalidator<TKey>. They run one after another, and each runs even when another throws; the exception, or an AggregateException of several, is thrown once they have all run.
public interface ITenantInvalidationHandler<in TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. SeeITenantDescriptor<TKey>for constraints.
Methods
InvalidateAllAsync(CancellationToken)
Clears what is kept for every tenant.
ValueTask InvalidateAllAsync(CancellationToken cancellationToken)Parameters:
cancellationTokenCancellationToken: Cancels the invalidation.
Returns: ValueTask: A task that completes when every tenant's data is cleared.
InvalidateAsync(TKey, CancellationToken)
Clears what is kept for the tenant tenantId.
ValueTask InvalidateAsync(TKey tenantId, CancellationToken cancellationToken)Parameters:
tenantIdTKey: The id of the tenant that changed.cancellationTokenCancellationToken: Cancels the invalidation.
Returns: ValueTask: A task that completes when the tenant's data is cleared.
ITenantEntity<TKey> interface
Marks an entity that belongs to a tenant.
ITenantInvalidator<TKey> interface
Clears everything Tenantry keeps for a tenant when the tenant changes: its cached copy with CacheTenants and what each ITenantInvalidationHandler<TKey>tenantry-itenantinvalidationhandler.md keeps, such as Tenantry.Caching's entries, cached responses and Tenantry.Options' values.