TenantPropagationAdapter class
Namespace: Tenantry.Pro · Package: Tenantry.Pro · API reference
An extension point: for code that extends the package, such as another package that builds on it. An application rarely needs it.
Registers a tenant-propagation adapter (ITenantPropagationAdapter) for its pro.Add…Propagation() method, as Tenantry.Pro's Hangfire, MassTransit, Quartz.NET and Rebus integrations do, and formats the tenant ids its WithTenant methods take.
public static IProBuilder<TKey> AddKafkaPropagation<TKey>(this IProBuilder<TKey> pro, Action<TenantPropagationOptions>? configure = null)
where TKey : IEquatable<TKey>, IParsable<TKey>
{
TenantPropagationAdapter.Add<TKey, KafkaPropagation>(pro, "Kafka", configure);
return pro;
}[EditorBrowsable(EditorBrowsableState.Advanced)]
public static class TenantPropagationAdapterMethods
Add<TKey, TAdapter>(IProBuilder<TKey>, string, Action<TenantPropagationOptions>?)
Registers TAdapter, and TenantPropagationIntegration<TAdapter> with its options, named name and configured by configure, as singletons; the propagator for the key type, which UsePro registers too; and the check that fails the host's start if the adapter's host side never ran (ITenantPropagationAdapter).
public static void Add<TKey, TAdapter>(IProBuilder<TKey> pro, string name, Action<TenantPropagationOptions>? configure = null) where TKey : IEquatable<TKey>, IParsable<TKey> where TAdapter : class, ITenantPropagationAdapterType parameters:
TKey: The tenant identifier type.TAdapter: The adapter.
Parameters:
proIProBuilder<TKey>: The Pro builder.namestring: The name of the adapter'sTenantPropagationOptions, such asKafka: also configurable withservices.Configure<TenantPropagationOptions>(name, …), and named in their validation error.configureAction<TenantPropagationOptions>: Configures the adapter's options, or null.
Exceptions:
ArgumentNullException:proornameis null.ArgumentException:nameis empty or white space.
Calling it again for the same adapter adds configure to the same options, and registers nothing more. Options with a TenantPropagationBehavior that is not defined stop the host from starting with OptionsValidationException.
FormatTenantId<TKey>(TKey, string?)
Formats a tenant id the application gives a job or message, for a WithTenant method, as ITenantPropagator.CurrentTenantId carries the current tenant's: with the invariant culture (Format<TKey>(TKey)). Refuses the ids Tenantry reserves for "no tenant".
public static string FormatTenantId<TKey>(TKey tenantId, string? paramName = null) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
tenantIdTKey: The tenant's id.paramNamestring: The name of the caller's parameter, for the exception; by default the expression passed.
Returns: string: The id as text, for the job's or message's HeaderName header.
Exceptions:
ArgumentNullException:tenantIdis null.ArgumentException:tenantIdis the key type's default value (Guid.Empty,0) or an empty string, which Tenantry reserves for "no tenant".
headers[TenantPropagation.HeaderName] = TenantPropagationAdapter.FormatTenantId(tenantId);