Skip to content

Domain Interfaces ​

Core abstractions for domain entities.

IEntity ​

MemberTypeDescription
IdGuidUnique identifier
CreatedAtDateTimeCreation timestamp
IsDeletedboolSoft delete flag

IEntity<TKey> ​

Same as IEntity but with custom key type.

IAuditable ​

MemberTypeDescription
CreatedAtDateTimeCreation timestamp
UpdatedAtDateTime?Last update timestamp
CreatedByGuid?Creator ID
UpdatedByGuid?Last updater ID

ISoftDeletable ​

MemberTypeDescription
IsDeletedboolDeleted flag
DeletedAtDateTime?Deletion timestamp
DeletedByGuid?Who deleted
Delete(Guid?)voidMark as deleted
Restore()voidRestore 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.

InterfaceMemberTypeDescription
IRequireTenantTenantIdGuidThe row always has an owner
IOptionalTenantTenantIdGuid?Null means a global row

IAggregateRoot ​

MemberTypeDescription
DomainEventsIReadOnlyCollection<DomainEvent>Pending events
AddDomainEvent(DomainEvent)voidAdd event
RemoveDomainEvent(DomainEvent)voidRemove event
ClearDomainEvents()voidClear 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.

Released under the MIT License.