Tenantry ProAPI reference
TenantryProMassTransitBuilderExtensions class
Namespace: Microsoft.Extensions.DependencyInjection · Package: Tenantry.Pro.MassTransit · API reference
Extension methods for adding the MassTransit integration on IProBuilder<TKey>.
public static class TenantryProMassTransitBuilderExtensionsMethods
AddMassTransitPropagation<TKey>(IProBuilder<TKey>, Action<TenantPropagationOptions>?)
Makes a message published or sent while a tenant is current carry the tenant in a header, and makes that tenant current while the message is consumed: the consumer, and the scoped services it takes, see it. Wire it into the bus with cfg.UseTenantry(context).
public static IProBuilder<TKey> AddMassTransitPropagation<TKey>(this IProBuilder<TKey> pro, Action<TenantPropagationOptions>? configure = null) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
proIProBuilder<TKey>: The Pro builder.configureAction<TenantPropagationOptions>: Sets what happens to a message that carries no tenant (TenantPropagationOptions.OnMissingTenant, Warn by default) or a tenant the store does not have (TenantPropagationOptions.OnUnresolvedTenant, Reject by default).
Returns: IProBuilder<TKey>: The same pro for chaining.
The application fails to start if the bus configuration never calls cfg.UseTenantry(context), which would leave messages without their tenant. Calling this again adds configure to the same options.
builder.Services.AddTenantry<string>(tenant => tenant
.UseStore<MyTenantStore>()
.UsePro(pro => pro.AddMassTransitPropagation()));
builder.Services.AddMassTransit(x =>
{
x.AddConsumer<OrderPlacedConsumer>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.UseTenantry(context);
cfg.ConfigureEndpoints(context);
});
});