Ledon.Data.MultiTenancy
0.0.1
dotnet add package Ledon.Data.MultiTenancy --version 0.0.1
NuGet\Install-Package Ledon.Data.MultiTenancy -Version 0.0.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="Ledon.Data.MultiTenancy" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ledon.Data.MultiTenancy" Version="0.0.1" />
<PackageReference Include="Ledon.Data.MultiTenancy" />
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 Ledon.Data.MultiTenancy --version 0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ledon.Data.MultiTenancy, 0.0.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 Ledon.Data.MultiTenancy@0.0.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=Ledon.Data.MultiTenancy&version=0.0.1
#tool nuget:?package=Ledon.Data.MultiTenancy&version=0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Ledon.Data.MultiTenancy
按租户路由数据库连接(库/schema 物理隔离),复用 Ledon.MultiTenancy 的租户解析和 Ledon.MultiTenancy.Management 的租户目录。
builder.Services.AddLedonMultiTenancy();
builder.Services.AddLedonTenantManagement();
builder.Services.AddLedonTenantData<AppDbContext>(o =>
{
o.DefaultConnectionString = configuration.GetConnectionString("Default");
o.ConfigureDbContext = (db, connectionString) => db.UseNpgsql(connectionString);
o.MigrationStrategy = LedonMigrationStrategy.MigrateOnly;
});
解析连接串:
public class OrdersService(ITenantDbContextFactory<AppDbContext> factory)
{
public async Task<List<Order>> ListAsync(CancellationToken ct)
{
await using var db = await factory.CreateAsync(ct: ct); // 当前租户
return await db.Orders.ToListAsync(ct);
}
}
迁移编排:
var orchestrator = scope.ServiceProvider.GetRequiredService<ITenantMigrationOrchestrator<AppDbContext>>();
var results = await orchestrator.MigrateAllAsync(); // 默认库 + 所有启用租户
规则:
- 租户未配置
ConnectionString时回退DefaultConnectionString(单库 + TenantId 过滤模式); - 租户停用/不存在/无连接串分别抛出明确异常;
ITenantDbContextFactory<T>、ITenantMigrationOrchestrator<T>是 Scoped,调用方负责释放 DbContext;MigrateAllAsync汇总每个租户的结果(成功/失败/挂起数),单个租户失败不会中断其余租户;- 共享库与租户库都迁移时,
<default>会先执行。
| Product | Versions 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.
-
net10.0
- Asp.Versioning.Http (>= 10.2.3)
- Asp.Versioning.Mvc (>= 10.2.1)
- Ledon.Data (>= 0.0.1)
- Ledon.MultiTenancy (>= 0.0.1)
- Ledon.MultiTenancy.Management (>= 0.0.1)
- Microsoft.AspNetCore.DataProtection.StackExchangeRedis (>= 10.0.13)
- Microsoft.AspNetCore.OpenApi (>= 10.0.13)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.13)
- Microsoft.Extensions.Caching.Hybrid (>= 10.11.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.13)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.DependencyModel (>= 10.0.13)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Scalar.AspNetCore (>= 2.18.3)
- StackExchange.Redis (>= 2.7.27)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.1 | 62 | 10/28/2026 |