Advertisement
Advanced ASP.NET Core, Configuration & Options Pattern

How would you design configuration for a multi-tenant ASP.NET Core application where each tenant needs different settings resolved at runtime?

Short answer

Since the standard Options pattern's IOptionsSnapshot is scoped per-request but not inherently tenant-aware, a common approach implements a custom tenant-aware settings resolver service that layers tenant-specific database or cache overrides on top of a global default…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Since the standard Options pattern's IOptionsSnapshot is scoped per-request but not inherently tenant-aware, a common approach implements a custom tenant-aware settings resolver service that layers tenant-specific database or cache overrides on top of a global default IOptionsMonitor<T> baseline, resolving the current tenant's specific configuration based on request context (subdomain, header, or claim) rather than relying on the built-in Options pattern alone.
public class TenantSettingsResolver(IOptionsMonitor<Dictionary<string, TenantSettings>> allSettings, ITenantContext tenantContext) {
    public TenantSettings GetCurrent() {
        return allSettings.CurrentValue.TryGetValue(tenantContext.TenantId, out var settings)
            ? settings
            : _defaultSettings;
    }
}
Real-world example
A B2B SaaS platform resolves each tenant's custom branding colors, feature flags, and rate limits through a tenant-aware settings resolver that layers tenant-specific database overrides on top of a global default configuration baseline.
Likely follow-ups
  • How do you cache tenant-specific settings efficiently without a database hit on every request?
  • How does this pattern interact with configuration hot-reload for tenant-specific changes?
Related topics