一个针对.NET 10的数据库每租户多租户构建模块,提供动态连接解析、JWT租户声明校验、三层缓存、基于计划的特性标志和配额、每租户弹性以及迁移工具。

Stars

8

7 天增长

暂无数据

Fork 数

0

开放 Issue

0

开源协议

暂无数据

最近更新

2026-07-30

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它为.NET 10提供了一个完整、生产就绪的多租户解决方案,包括租户感知的JWT、三层缓存和每租户断路器,并附有详细的设计文档和经过验证的端到端流程。

适合谁使用

  • 构建多租户SaaS应用的.NET开发者
  • 设计租户隔离策略的架构师
  • 管理每租户数据库部署的DevOps工程师
  • 需要基于计划特性开关和配额限制的团队

典型使用场景

  • 为每个租户构建具有独立数据库的多租户SaaS后端
  • 动态解析并缓存每个租户的数据库连接字符串
  • 对每个租户执行数据库迁移,实现故障隔离
  • 实现基于计划的特性标志和速率限制

项目优势

  • 完整的解决方案,附有详细的设计文档(SDD.md)
  • 经过验证的端到端流程(冷启动步骤)且所有测试通过(11个单元测试,39个集成测试)
  • 包含每租户弹性机制(可配置超时和断路器模式)
  • 迁移工具支持每租户故障隔离和空运行预览

使用前须知

  • 容器化API无法使用种子演示租户,因为DbHost硬编码为'localhost'(仅当在宿主机上运行并通过Docker发布端口时有效)
  • 断路器和/health/tenants电路状态的自动测试尚未实现
  • EF Core 10未将租户完整迁移批次封装在一个事务中,因此部分批次失败需要手动检查架构状态

README 快速开始

SaaS Multi-Tenant Isolation Engine

A Database-per-Tenant multi-tenancy building block for .NET 10: dynamic per-tenant connection resolution, JWT authentication with tenant-claim cross-checking, a three-layer tenant metadata cache, plan-based feature flags/quotas, per-tenant resilience (timeout + circuit breaker), and a migration tool with per-tenant failure isolation.

See docs/SDD.md for the full design rationale.

Solution layout

src/BuildingBlocks/BuildingBlocks.MultiTenancy/   Reusable multi-tenancy plumbing (no DB dependency)
src/Services/Catalog.Admin/                       Central catalog: Plan/Tenant/PlanFeature/PlanQuota + EF store
src/Services/SaaS.CoreEngine.Api/                 The tenant-facing API (billing domain demo: Customer/Product/Invoice)
src/Tools/Tools.DbMigrator/                        Sweeps active tenants and applies pending migrations
tests/BuildingBlocks.MultiTenancy.UnitTests/       Pure unit tests, no Docker required
tests/SaaS.CoreEngine.IntegrationTests/            Testcontainers-backed integration tests (require Docker)
docker/postgres-tenants/init/                      First-boot script creating the demo tenant databases
docker-compose.yml                                 Local dev stack: postgres-central, postgres-tenants, redis, api

Prerequisites

  • .NET SDK 10.0+
  • Docker Desktop (for docker compose and for the Testcontainers-backed integration tests)
  • dotnet-ef global tool (dotnet tool install --global dotnet-ef), matching the EF Core version pinned in Directory.Packages.props

Cold start (verified flow)

This is the exact sequence that was run and verified end-to-end for this repository. It runs the API and Tools.DbMigrator on the host via dotnet run, with Postgres and Redis provided by docker-compose — not the containerized api service (see "Known limitation" below).

# 1. Copy the environment template (edit if you need non-default ports/credentials)
Copy-Item .env.example .env

# 2. Start Postgres (catalog + tenants cluster) and Redis
docker compose up -d postgres-central postgres-tenants redis

# 3. Wait for all three to report healthy
docker compose ps

# 4. Apply the catalog migration
$env:DOTNET_CATALOG_CONNECTION = "Host=localhost;Port=5433;Database=saas_catalog;Username=postgres;Password=postgres"
dotnet ef database update --project src/Se

项目描述

Database-per-Tenant multi-tenancy engine for .NET 10 — dynamic per-tenant connection resolution, JWT auth with tenant-claim cross-checking, plan-based feature flags/quotas, per-tenant resilience (circuit breaker + bulkhead), and a zero-downtime migration tool.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

programmersd21
精选
programmersd21 GitHub avatar

flow

flow is a minimalist terminal dashboard that displays real-time network throughput with smooth animations, multiple responsive modes, and zero configuration.

开发者工具CLI 与终端
277
S40911120
精选
S40911120 GitHub avatar

recensa

Recensa is a self-hosted web viewer that indexes Claude Code session transcripts into a local SQLite database, enabling full-text search, replay, and audit of all past agent conversations without uploading data anywhere.

AI 与机器学习大语言模型
67
0xwilliamortiz
精选
0xwilliamortiz GitHub avatar

openclaude-improved

OpenClaude is an open-source CLI coding agent that runs on any platform and supports a wide range of LLM providers, offering the same tools and workflows as Claude Code.

AI 与机器学习大语言模型
577