Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Testing/CoreTests/Acceptance/multi_tenancy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public async Task InitializeAsync()
.UseWolverine(opts =>
{
opts.Services.AddSingleton(theTracker);

opts.Durability.TenantIdStyle = TenantIdStyle.ForceLowerCase;
})
.StartAsync();
}
Expand All @@ -29,6 +31,15 @@ public async Task DisposeAsync()
await _host.StopAsync();
}

[Fact]
public void maybe_corrects_tenant_id_on_set()
{
var context = _host.MessageBus();
context.TenantId = "WRONG_CASE";

context.TenantId.ShouldBe("wrong_case");
}

[Fact]
public async Task invoke_with_tenant()
{
Expand Down
10 changes: 8 additions & 2 deletions src/Wolverine/Runtime/MessageBus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using JasperFx.Core;
using JasperFx.MultiTenancy;
using Wolverine.Persistence.Durability;
using Wolverine.Runtime.Routing;
using Wolverine.Transports;
Expand All @@ -13,7 +14,8 @@ public static MessageBus Build(IWolverineRuntime runtime, string correlationId)

// ReSharper disable once InconsistentNaming
protected readonly List<Envelope> _outstanding = new();

private string? _tenantId;

public MessageBus(IWolverineRuntime runtime) : this(runtime, Activity.Current?.RootId ?? Guid.NewGuid().ToString())
{
}
Expand Down Expand Up @@ -49,7 +51,11 @@ private void assertNotMediatorOnly()
public IEnvelopeTransaction? Transaction { get; protected set; }
public Guid ConversationId { get; protected set; }

public string? TenantId { get; set; }
public string? TenantId
{
get => _tenantId;
set => _tenantId = Runtime.Options.Durability.TenantIdStyle.MaybeCorrectTenantId(value);
}

public IDestinationEndpoint EndpointFor(string endpointName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Wolverine/Runtime/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public MessageContext(IWolverineRuntime runtime) : base(runtime)
// Used implicitly in codegen
public MessageContext(IWolverineRuntime runtime, string tenantId) : base(runtime)
{
TenantId = tenantId;
TenantId = runtime.Options.Durability.TenantIdStyle.MaybeCorrectTenantId(tenantId);
}

internal IList<Envelope> Scheduled { get; } = new List<Envelope>();
Expand Down
Loading