Docs
Tenantry ProAPI reference

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 TenantPropagationAdapter

Methods

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, ITenantPropagationAdapter

Type parameters:

  • TKey: The tenant identifier type.
  • TAdapter: The adapter.

Parameters:

  • pro IProBuilder<TKey>: The Pro builder.
  • name string: The name of the adapter's TenantPropagationOptions, such as Kafka: also configurable with services.Configure<TenantPropagationOptions>(name, …), and named in their validation error.
  • configure Action<TenantPropagationOptions>: Configures the adapter's options, or null.

Exceptions:

  • ArgumentNullException: pro or name is null.
  • ArgumentException: name is 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:

  • tenantId TKey: The tenant's id.
  • paramName string: 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: tenantId is null.
  • ArgumentException: tenantId is 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);

On this page