Making.MultiTenancy.Abstractions 1.0.9-preview

This is a prerelease version of Making.MultiTenancy.Abstractions.
dotnet add package Making.MultiTenancy.Abstractions --version 1.0.9-preview
                    
NuGet\Install-Package Making.MultiTenancy.Abstractions -Version 1.0.9-preview
                    
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="Making.MultiTenancy.Abstractions" Version="1.0.9-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Making.MultiTenancy.Abstractions" Version="1.0.9-preview" />
                    
Directory.Packages.props
<PackageReference Include="Making.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 Making.MultiTenancy.Abstractions --version 1.0.9-preview
                    
#r "nuget: Making.MultiTenancy.Abstractions, 1.0.9-preview"
                    
#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 Making.MultiTenancy.Abstractions@1.0.9-preview
                    
#: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=Making.MultiTenancy.Abstractions&version=1.0.9-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Making.MultiTenancy.Abstractions&version=1.0.9-preview&prerelease
                    
Install as a Cake Tool

Making.MultiTenancy.Abstractions

Multi-tenancy abstractions and interfaces for the Making framework.

Overview

Making.MultiTenancy.Abstractions provides the core abstractions and interfaces for implementing multi-tenant applications with the Making framework. It defines contracts for tenant information, current tenant access, and tenant resolution strategies.

Features

  • Tenant Abstractions: Core interfaces for tenant management
  • Current Tenant Access: Interface for accessing current tenant context
  • Tenant Information: Basic tenant information model
  • Provider Abstraction: Abstraction layer for different tenancy strategies
  • Thread-Safe Access: Safe concurrent access to tenant context

Installation

dotnet add package Making.MultiTenancy.Abstractions

Usage

Tenant Information Interface

public interface ITenantInfo
{
    string Id { get; }
    string Name { get; }
    string ConnectionString { get; }
    Dictionary<string, object> Properties { get; }
}

public class BasicTenantInfo : ITenantInfo
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string ConnectionString { get; set; }
    public Dictionary<string, object> Properties { get; set; } = new();
}

Current Tenant Interface

public interface ICurrentTenant
{
    string Id { get; }
    string Name { get; }
    bool IsAvailable { get; }
    ITenantInfo TenantInfo { get; }
    
    IDisposable Change(string tenantId);
}

Current Tenant Accessor

public interface ICurrentTenantAccessor
{
    ITenantInfo Current { get; set; }
}

Using in Services

public class OrderService
{
    private readonly ICurrentTenant _currentTenant;
    private readonly IOrderRepository _orderRepository;
    
    public OrderService(ICurrentTenant currentTenant, IOrderRepository orderRepository)
    {
        _currentTenant = currentTenant;
        _orderRepository = orderRepository;
    }
    
    public async Task<List<Order>> GetOrdersAsync()
    {
        // Automatically filter by current tenant
        var tenantId = _currentTenant.Id;
        return await _orderRepository.GetByTenantAsync(tenantId);
    }
    
    public async Task<Order> CreateOrderAsync(CreateOrderRequest request)
    {
        var order = new Order
        {
            TenantId = _currentTenant.Id,
            CustomerName = request.CustomerName,
            Items = request.Items,
            CreatedAt = DateTime.UtcNow
        };
        
        return await _orderRepository.CreateAsync(order);
    }
}

Tenant Context Switching

public class AdminService
{
    private readonly ICurrentTenant _currentTenant;
    private readonly IUserService _userService;
    
    public AdminService(ICurrentTenant currentTenant, IUserService userService)
    {
        _currentTenant = currentTenant;
        _userService = userService;
    }
    
    public async Task<List<User>> GetAllUsersAcrossTenantsAsync(List<string> tenantIds)
    {
        var allUsers = new List<User>();
        
        foreach (var tenantId in tenantIds)
        {
            // Switch tenant context
            using (_currentTenant.Change(tenantId))
            {
                var tenantUsers = await _userService.GetUsersAsync();
                allUsers.AddRange(tenantUsers);
            }
        }
        
        return allUsers;
    }
}

Custom Tenant Implementation

public class CompanyTenant : ITenantInfo
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string ConnectionString { get; set; }
    public Dictionary<string, object> Properties { get; set; } = new();
    
    // Custom properties
    public string CompanyCode { get; set; }
    public string TimeZone { get; set; }
    public string CurrencyCode { get; set; }
    public bool IsActive { get; set; }
    public DateTime CreatedAt { get; set; }
}

public class CompanyTenantService
{
    private readonly ICurrentTenant _currentTenant;
    
    public CompanyTenantService(ICurrentTenant currentTenant)
    {
        _currentTenant = currentTenant;
    }
    
    public CompanyTenant GetCurrentCompany()
    {
        return _currentTenant.TenantInfo as CompanyTenant;
    }
    
    public string GetCurrentTimeZone()
    {
        var company = GetCurrentCompany();
        return company?.TimeZone ?? "UTC";
    }
    
    public string GetCurrentCurrency()
    {
        var company = GetCurrentCompany();
        return company?.CurrencyCode ?? "USD";
    }
}

Repository Pattern with Multi-Tenancy

public interface ITenantAwareRepository<T> where T : class
{
    Task<T> GetByIdAsync(object id);
    Task<List<T>> GetAllAsync();
    Task<T> CreateAsync(T entity);
    Task UpdateAsync(T entity);
    Task DeleteAsync(object id);
}

public abstract class TenantAwareRepository<T> : ITenantAwareRepository<T> where T : class, ITenantEntity
{
    protected readonly ICurrentTenant _currentTenant;
    
    protected TenantAwareRepository(ICurrentTenant currentTenant)
    {
        _currentTenant = currentTenant;
    }
    
    public virtual async Task<List<T>> GetAllAsync()
    {
        var tenantId = _currentTenant.Id;
        return await GetByTenantAsync(tenantId);
    }
    
    protected abstract Task<List<T>> GetByTenantAsync(string tenantId);
}

public interface ITenantEntity
{
    string TenantId { get; set; }
}

Requirements

  • .NET Standard 2.0+

License

This project is part of the Making framework.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Making.MultiTenancy.Abstractions:

Package Downloads
Making.MultiTenancy

Multi-tenancy implementation and services for the Making framework

Making.EntityFrameworkCore

Entity Framework Core integration for the Making framework

Making.Localization

Comprehensive localization and internationalization support for the Making framework

Making.Ddd.Domain.Shared

Making framework for building modern applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9-preview 89 8/20/2025
1.0.8-preview 89 8/20/2025
1.0.6-preview 90 8/19/2025
1.0.4-preview 111 8/10/2025
1.0.1-preview 330 7/25/2025
1.0.0-preview 404 7/25/2025