Visualize and test enterprise-grade tenant isolation and resolution strategies.
Generate the foundation for Your SaaS multi-tenancy model.
// Program.cs
builder.Services.AddPrimusMultiTenancy(options => {
// Choose resolution strategy: Subdomain, Header, or Path
options.ResolutionStrategy = TenantResolutionStrategy.Subdomain;
// Data isolation approach
options.IsolationStrategy = TenantIsolationStrategy.SchemaPerTenant;
// Connection string template for isolated DBs
options.ConnectionStringTemplate = "Server=.;Database=Primus_{TenantId};Trusted_Connection=true;";
// Enable tenant caching for performance
options.EnableTenantCache = true;
options.TenantCacheDuration = TimeSpan.FromMinutes(10);
});
// Middleware setup (order matters)
app.UsePrimusTenantResolution();
app.UsePrimusTenantContext();
// Access current tenant in your services
public class MyService {
private readonly ITenantContext _tenant;
public MyService(ITenantContext tenant) {
_tenant = tenant;
}
public async Task DoWork() {
var tenantId = _tenant.Current.Id;
var schema = _tenant.Current.Schema;
// Queries automatically scoped to tenant
}
}
Test how Primus resolves tenants and routes data interactively.
# Waiting for incoming request signal...
# Simulator will trace context propagation and DB selection