AspNano.Domain is a class library which contains the entity classes. These entity classes model the underlying database by means of Entity Framework and code-first migrations. Conceptually, The domain project is at the lowest level in the application.
The domain project organizes entities into three folders.
- Catalog – for business entities
- Common – for base entities (abstract classes)
- Multitenancy – for the tenant entity
The domain entities define the business rules in the application. In other words, the classes here create the tables and relationships in a database.
The Venue entity is a sample business entity. Use it as a guide for creating new entities. It inherits from the AuditableEntity abstract class, which in turn inherits from the, TenantBaseEntity, which inherits from the BaseEntity<Guid>. Generally any entity that is tenant isolated should use a Guid as the ID type.
The tenant entity uses magic strings for IDs solely for simplicity. Depending on the needs of your application, tenant attributes like subscription level, expiry dates, etc. can be added here. Migrations for the tenant entity should be run against the BaseDbContext.
The BaseEntity<T> contains one property, Id, which is a generic type. All entities should derive from this directly or indirectly. This class is an abstract class which means that it will only be used to create other entities.
The TenantBaseEntity contains one property, TenantId and implements the IMustHaveTenant interface. Any tenant isolated entities should inherit from this abstract class.
The AuditableEntity class contains properties for CreatedBy, CreatedOn, LastModifiedBy, LastModifiedOn, DeletedBy, DeletedOn, and IsDeleted. It is also an abstract class, and inherits from the BaseEntity. It implements the IAudiableEntity, and ISoftDelete interfaces.
It’s recommended to create entity classes that inherit from AuditableEntity. Entity types that derive from this will have audit field data handled automatically in the OnSaveChanges override (explained in the persistence section of the infrastructure document).
Creating Non-Tenant Entities
To create entities that are visible across all tenants, don’t implement the IMustHaveTenant interface. The recommended approach is to inherit from the BaseEntity directly and implement IAuditableEntity and ISoftDelete if you need those.