Abpzero-Multi-tenant management
Enable multi-tenancy
The ASP. Boilerplate and Module-zero can run multi-tenant or single-tenant mode. Multi-tenancy is disabled by default. We can enable it in our module Preinitialize method to make it as follows:
[DependsOn (typeof (Abpzerocoremodule))]
public class Mycoremodule:abpmodule
{
public override void Preinitialize ()
{
Configuration.MultiTenancy.IsEnabled = true;
}
...
}
It is important to note that even if our application is not multi-tenancy, we must define a default tenant (see the default tenant section of this file).
When we create a project template based on ASP. Boilerplate and Module-zero, we have a tenant's entity and Tenantmanager Domain Services.
Tenant Entity
The tenant entity represents a tenant for the application.
public class Tenant:abptenant<tenant, user>
{
}
It originates from the generic class abptenant. The tenant entity is stored in the Abptenants table of the database. You can add custom attributes to the tenant class.
The Abptenant class defines some basic properties, and most importantly:
Tenancyname: This is the unique name of a tenant in the application. It should not normally be changed. It can be used to assign subdomains to tenants such as "mytenant.mydomain.com".
Tenant.tenancynameregex constants define naming conventions.
Name: An arbitrary, human-readable, long-name tenant.
Isactive:true, this tenant can use the application. If it is false, no user can log on to the system for this tenant.
The Abptenant class is inherited from Fullauditedentity. This means that it has the create, modify, and delete audit properties. This is also soft delete. So when we delete the tenant, it is not deleted from the database, just marked for deletion.
Finally, the ID of the abptenant is defined as int.
Tenant Manager
Tenant Manager is a service that tenants perform domain logic for:
public class Tenantmanager:abptenantmanager<tenant, Role, user>
{
Public Tenantmanager (irepository<tenant> tenantrepository)
: Base (Tenantrepository)
{
}
}
You can add your own method here. You can also overwrite any method of the Abptenantmanager base class against your own needs.
Default Tenant
The ASP. Boilerplate and Module-zero assume that there is a pre-defined tenant whose tenancyname is "Default" and the ID is 1. In a single-tenant application, this is used as a single tenant. In a multi-tenant application, you can delete it or invalidate it.
ABP Zero Multi-tenant management