TenantScopedEntity
Base classes for multi-tenant entities with automatic tenant isolation.
TenantScopedEntity
For simple tenant-scoped entities without domain events.
Properties
| Property | Type | Description |
|---|---|---|
| TenantId | Guid | The tenant this entity belongs to |
Plus all properties from BaseEntity.
Constructor
| Parameter | Type | Description |
|---|---|---|
| tenantId | Guid | Required. Cannot be empty. |
Usage
csharp
public class Product : TenantScopedEntity
{
public string Name { get; private set; }
public decimal Price { get; private set; }
private Product() { }
public Product(Guid tenantId, string name, decimal price)
: base(tenantId)
{
Name = name;
Price = price;
}
}TenantScopedAggregateRoot
For tenant-scoped aggregate roots that need domain events.
Properties
| Property | Type | Description |
|---|---|---|
| TenantId | Guid | The tenant this aggregate belongs to |
Plus all from AggregateRoot: Id, DomainEvents, etc.
Usage
csharp
public class Order : TenantScopedAggregateRoot
{
public string OrderNumber { get; private set; }
private Order() { }
public Order(Guid tenantId, string orderNumber)
: base(tenantId)
{
OrderNumber = orderNumber;
RaiseDomainEvent(new OrderCreatedEvent(Id, tenantId));
}
}When to Use
| Scenario | Use |
|---|---|
| Simple tenant entity | TenantScopedEntity |
| Aggregate with events | TenantScopedAggregateRoot |
| No tenant isolation | BaseEntity or AggregateRoot |