dotnet-multi-tenant

Implement per-tenant isolation in .NET APIs with JWT secrets and DbContext factories.

1|Updated Feb 10, 2026
One-click install
npx skills add https://github.com/landim32/awesome-ai-skills --skill dotnet-multi-tenant-landim32
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-multi-tenant
Source: https://github.com/landim32/awesome-ai-skills/tree/main/skills/dotnet-multi-tenant
Command: npx skills add https://github.com/landim32/awesome-ai-skills --skill dotnet-multi-tenant-landim32

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implements a robust multi-tenant pattern for .NET APIs, enabling per-tenant database isolation, per-tenant JWT secrets, and automatic TenantId propagation across API and ACL layers.

Core Features & Use Cases

  • Per-tenant resolution via header or JWT claims
  • Dynamic per-tenant JWT secrets for token validation
  • Per-tenant DbContext creation using a factory
  • End-to-end tenant-aware authentication and ACL propagation

Quick Start

Configure your startup to wire TenantMiddleware before authentication and use the scoped TenantDbContextFactory for per-tenant DbContexts.

Frequently Asked Questions about dotnet-multi-tenant

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement multi-tenant isolation in an ASP.NET Core API?

Multi-tenant isolation in an ASP.NET Core API is implemented by using middleware to resolve tenants from headers or JWT claims, dynamically validating per-tenant JWT secrets, and routing requests to per-tenant databases via a scoped DbContext factory.

Can I validate JWT tokens using different secrets for each tenant in .NET?

Yes, you can validate JWT tokens using different secrets for each tenant in .NET by employing dynamic JWT secret lookup. The system resolves the tenant context first, then applies the specific tenant's secret to validate the token signature.

How do I propagate TenantId through middleware and ACL layers without modifying existing models?

You propagate TenantId through middleware and ACL layers without modifying existing models by utilizing TenantMiddleware and scoped dependency injection patterns. This automatically flows the TenantContext across API and supporting layers without requiring structural model changes.

What is the best way to create a per-tenant DbContext in .NET?

The best way to create a per-tenant DbContext in .NET is using a TenantDbContextFactory. This factory generates scoped DbContext instances configured with per-tenant database connections, ensuring complete data isolation based on the resolved TenantContext.

Does this multi-tenant .NET pattern require modifying existing DbContext models?

No, this multi-tenant .NET pattern does not require modifying existing DbContext models. It achieves per-tenant database isolation and automatic TenantId propagation through scoped dependency injection and a DbContext factory without altering your existing models or DbContext structure.