public static TenantContextOverride Push(ITenant tenant) { var newTenants = CurrentLocal.Value; var tenantContext = new TenantContextOverride(tenant); newTenants = newTenants != null?newTenants.Append(tenantContext).ToArray() : new[] { tenantContext }; CurrentLocal.Value = newTenants; return(tenantContext); }
public async Task <object> HandleAsync(ICommandBase command, CommandExecutionOptions executionOptions, CommandBusMiddlewareDelegate next, CancellationToken cancellationToken) { if (executionOptions.TenantContext != null) { using (TenantContextOverride.Push(executionOptions.TenantContext.Tenant)) { return(await next(command)); } } else { return(await next(command)); } }