Multi-Tenant

tenant

Overview

Multi-tenancy (SaaS) is a software architecture that allows a single software instance to serve multiple tenants (such as enterprises, organizations, or individuals) simultaneously. Each tenant has its own independent database, ensuring complete physical data isolation, as if each tenant were using a dedicated software instance.

Core Advantages

  • Cost Efficiency: Multiple tenants share the underlying software infrastructure, reducing development, deployment, and maintenance costs
  • Rapid Deployment: New tenants can quickly access the system without lengthy software installation and configuration processes
  • Unified Management: All tenants are managed centrally on one platform, improving management efficiency
  • Data Security: Each tenant has its own independent database, providing natural physical isolation to prevent data leakage risks

Usage

Enabling Multi-Tenancy

Add the AddEasyAdminBlazorMultiTenant() extension method in Program.cs to automatically enable multi-tenancy:

builder.AddEasyAdminBlazor(new EasyAdminBlazorOptions { ... })
    .AddEasyAdminBlazorMultiTenant();

Tenant Identification

The system automatically identifies the current tenant using the request's Host (domain name). Each tenant is bound to a unique domain, for example:

  • https://tenant1.yourdomain.com → Identified as tenant1
  • https://localhost:7230 → Development environment distinguished by port

The tenant's Host field supports three formats: localhost:7230, https://localhost:7230, http://localhost:7230.

Adding a Tenant (Admin Perspective)

  1. Log in to the system admin console and navigate to the "Multi-Tenant" module.
  2. Click the "Add" button and fill in the following in the dialog:
    • Basic Settings: Tenant code (unique identifier, e.g., vip), domain name, database type, connection string, name, description
    • Function Menu: Assign accessible menus to the tenant
  3. Click "Save", and the system automatically completes the following:
    • Creates a tenant record (in the master database)
    • Creates the tenant's admin role and initial admin account in the database
    • Synchronizes the selected menus to the tenant's database
    • Automatically creates tables (UseAutoSyncStructure)

Editing a Tenant

  1. Find the target tenant and click the "Edit" button.
  2. Modify basic information or adjust menu permissions.
  3. Menu changes are automatically synchronized to the tenant's database.

Deleting a Tenant

  1. Select the tenant(s) to delete (multiple selection allowed), and click "Delete".

Tenant Login

Tenants access the system via their own domain, using the automatically generated admin account created during setup. Default password format: {tenantCode}123 (e.g., vip123).

File Isolation

When multi-tenancy is enabled, uploaded files are automatically stored in directories segregated by tenant code: wwwroot/uploads/{tenantCode}/yyyy/MM/dd/.

Interface Description

Tenant List

  • Tenant Code: Unique identifier
  • Tenant Domain: Bound Host
  • Database Type: Type of database used (empty indicates using the shared database)
  • Tenant Name: Display name
  • Enabled: Enabled / Disabled
  • Created By / Created Time: Operation audit information

Edit Dialog

Contains two tabs:

  • Basic Settings: Code, domain, database type, connection string, name, description, enabled status
  • Function Menu: Menu tree for permission assignment (selecting a child menu automatically selects its parent menus)
  • SysTenant — Tenant entity
  • ITenantService / MultiTenantService — Tenant services
  • FreeSqlCloud — Multi-tenant database dispatching
  • MainOrmHandle — Master database ORM handle