XiHan.Framework.MultiTenancy.Abstractions 5.0.0-preview.1

Prefix Reserved
This is a prerelease version of XiHan.Framework.MultiTenancy.Abstractions.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package XiHan.Framework.MultiTenancy.Abstractions --version 5.0.0-preview.1
                    
NuGet\Install-Package XiHan.Framework.MultiTenancy.Abstractions -Version 5.0.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XiHan.Framework.MultiTenancy.Abstractions" Version="5.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XiHan.Framework.MultiTenancy.Abstractions" Version="5.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="XiHan.Framework.MultiTenancy.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XiHan.Framework.MultiTenancy.Abstractions --version 5.0.0-preview.1
                    
#r "nuget: XiHan.Framework.MultiTenancy.Abstractions, 5.0.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package XiHan.Framework.MultiTenancy.Abstractions@5.0.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XiHan.Framework.MultiTenancy.Abstractions&version=5.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XiHan.Framework.MultiTenancy.Abstractions&version=5.0.0-preview.1&prerelease
                    
Install as a Cake Tool

XiHan.Framework.MultiTenancy.Abstractions

多租户契约(Ring 2)。能力 multitenancy.context@1(租户解析、校验与存储)与 multitenancy.sharding@1(按租户选择数据连接)由 Provider 提供。

契约 用途
TenantInfo、TenantIdentifier 租户信息(ID、显示名、是否启用、属性)与 ID 文法
ITenantStore 按 ID 查找与枚举租户;Provider 实现它
ITenantResolver、ClaimTenantResolver、BaggageTenantResolver 从调用上下文解析租户 ID 候选;按注册顺序,先解析出的生效
MultiTenancyOptions 默认租户、是否必须有租户、是否核对存储、租户声明类型、分片缓存容量
TenantResolutionMiddleware Tenant 阶段:解析 → 校验格式 → 核对存储(存在且启用)→ 写入安全上下文 → 解析分片写入调用上下文(装配了解析器时;失败即调用失败)
ITenantShardResolver、TenantShard、TenantShardKeys、TenantStoreShardResolver 租户分片:解析器契约(ResolveAsync → Result<Maybe<TenantShard>>、Invalidate)、分片(连接串、小写提供者名、透传属性)、租户属性键(ConnectionString、DatabaseProvider、Shard.*)与从 ITenantStore 推出分片的默认解析器(按租户有界缓存)
TenantShardInvocationExtensions、TenantShardBinding 调用上下文里的分片(GetTenantShard / SetTenantShard)与持久化 Provider 在作用域内用的分片连接绑定(主值是分片连接串,属性并入分片属性与 tenant / provider;先看 TenantShardScope 的显式绑定,再看当前调用)
TenantShardScope 管道外的作用域显式绑定分片(ADR-0057):BindTenantAsync(tenantId) 经分片解析器解析并绑定(不看租户是否启用、不受应用状态影响,共库租户不绑定),Bind(shard) 直接绑定;须在作用域首次创建持久化客户端之前,之后再绑定或改绑抛出 InvalidOperationException。多租户 Provider 登记为作用域服务

解析顺序由 Provider 注册决定,默认先主体声明后 Baggage。Baggage 里的租户只来自进程内建上下文的地方(消息派发、作业、工作流、命令行宿主),HTTP、gRPC、MCP 的网络入站不收这个键(ADR-0121),这些调用方的租户只来自认证;CloudEvents 入站的 xihantenant 经消息派发进来,由宿主给端点加的权限把关。当前租户经 context.GetSecurity().Tenant 读取,没有环境态访问器。

分库:租户属性 ConnectionString 有值即分库,Tenant 阶段解析一次写进调用上下文,持久化 Provider(SqlSugar、EF Core)在作用域内按分片选连接;解析失败返回 MULTITENANCY_UNAVAILABLE_002,不降级为共库。租户连接变更后调用 ITenantShardResolver.Invalidate。分片库的表结构由应用管理。

依赖方向

依赖 XiHan.Framework.Kernel。被 MultiTenancy.InMemory 等实现包引用。

状态

P2:可用;P5 加入分片。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on XiHan.Framework.MultiTenancy.Abstractions:

Package Downloads
XiHan.Framework.Settings

曦寒框架设置库

XiHan.Framework.Caching

曦寒框架缓存库

XiHan.Framework.MultiTenancy

曦寒框架多租户库

XiHan.Framework.Tasks

曦寒框架任务库

XiHan.Framework.EventBus.Abstractions

曦寒框架事件总线抽象包

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on XiHan.Framework.MultiTenancy.Abstractions:

Repository Stars
XiHanFun/XiHan.BasicApp
A beautifully crafted general-purpose admin kernel built on XiHan.Framework and XiHan.UI. The basic application of the XiHanFun open-source ecosystem.
Version Downloads Last Updated
5.0.0-preview.2 43 11/6/2026
5.0.0-preview.1 67 11/4/2026
4.8.0 332 10/22/2026
4.7.1 264 10/21/2026
4.7.0 277 10/15/2026
4.6.2 267 10/13/2026
4.6.1 468 10/3/2026
4.6.0 272 9/25/2026
4.5.0 244 9/23/2026
4.4.0 245 9/22/2026
4.3.0 268 9/12/2026
4.2.0 301 9/4/2026
4.1.0 268 8/31/2026
4.0.0 258 8/28/2026
3.14.0 267 8/26/2026
3.13.0 288 8/15/2026
3.12.1 255 8/14/2026
3.12.0 517 8/13/2026
3.11.1 256 8/11/2026
3.11.0 498 8/11/2026
Loading failed