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" />
                    
Directory.Packages.props
<PackageReference Include="Ledon.Data.MultiTenancy" />
                    
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 Ledon.Data.MultiTenancy --version 0.0.1
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Ledon.Data.MultiTenancy&version=0.0.1
                    
Install as a Cake Tool

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> 会先执行。

完整文档:https://github.com/wosledon/ledon-framework

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

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