Appearance
Domain Interfaces
Core abstractions for domain entities.
IEntity
| Member | Type | Description |
|---|---|---|
| Id | Guid | Unique identifier |
| CreatedAt | DateTime | Creation timestamp |
| IsDeleted | bool | Soft delete flag |
IEntity<TKey>
Same as IEntity but with custom key type.
IAuditable
| Member | Type | Description |
|---|---|---|
| CreatedAt | DateTime | Creation timestamp |
| UpdatedAt | DateTime? | Last update timestamp |
| CreatedBy | Guid? | Creator ID |
| UpdatedBy | Guid? | Last updater ID |
ISoftDeletable
| Member | Type | Description |
|---|---|---|
| IsDeleted | bool | Deleted flag |
| DeletedAt | DateTime? | Deletion timestamp |
| DeletedBy | Guid? | Who deleted |
| Delete(Guid?) | void | Mark as deleted |
| Restore() | void | Restore entity |
Tenant markers
Every entity with a TenantId declares one of the two (ADR 0011, D22); an architecture test enforces it, with a short justified exception list.
| Interface | Member | Type | Description |
|---|---|---|---|
IRequireTenant | TenantId | Guid | The row always has an owner |
IOptionalTenant | TenantId | Guid? | Null means a global row |
IAggregateRoot
| Member | Type | Description |
|---|---|---|
| DomainEvents | IReadOnlyCollection<DomainEvent> | Pending events |
| AddDomainEvent(DomainEvent) | void | Add event |
| RemoveDomainEvent(DomainEvent) | void | Remove event |
| ClearDomainEvents() | void | Clear all events |
IAppendOnly
A marker without members for entities whose rows are only inserted, such as an event trail. The persistence pipeline refuses to update or delete them: AppendOnlyGuard.Enforce throws AppendOnlyEntityException (a programming error, so it surfaces as a 500, not a 409) for any tracked entity in the Modified or Deleted state. Added and Unchanged pass. A BaseEntity marked as deleted is refused too, not turned into a soft delete. A change to an owned type is refused as a change to its owner.
Wiring: options.UseGrydAuditableEntities(provider) already applies the guard. A context without the auditable interceptor calls services.AddGrydAppendOnlyEntities() and options.UseGrydAppendOnlyEntities(provider).
csharp
public sealed class TrailEvent : IAppendOnly
{
public Guid Id { get; init; }
public string Kind { get; init; } = string.Empty;
}Limit: ExecuteUpdate, ExecuteDelete and raw SQL do not go through SaveChanges, so the guard cannot see them. Enforce it in the database as well: run the application under a role that does not own the table (the owner can grant the privileges back) and revoke the writes.
sql
REVOKE UPDATE, DELETE, TRUNCATE ON <table> FROM <application role>;Retention or erasure (LGPD) needs a separate role that keeps DELETE.