Skip to content
Back to skills

Domain Layer Rules

ASecurity

Domain layer rules — zero external dependencies, entities, aggregate roots, value objects, domain events, and repository interfaces. Apply whenever writing or editing code in a Domain project.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 11, 2026
developmentc#

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add makigjuro/cloud-app-blueprint --skill domain-layer-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Domain Layer Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Domain Layer Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/makigjuro-domain-layer-rules/badge)](https://www.skillsdirectory.com/skills/makigjuro-domain-layer-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: domain-layer-rules
description: Domain layer rules — zero external dependencies, entities, aggregate roots, value objects, domain events, and repository interfaces. Apply whenever writing or editing code in a Domain project.
user-invocable: false
paths:
  - "src/**/Domain/**/*.cs"
---

# Domain Layer Rules

## Zero External Dependencies
- No references to Infrastructure, Host, EF Core, ASP.NET, or any framework
- Only pure C# and domain abstractions -- the Domain csproj has no package or project references
- `Result`/`Error` are NOT in Domain; they live in the shared infrastructure project (`Shared.Infrastructure/Results/`) and are used by Application handlers

## Entities
- Inherit from `Entity<TId>` where `TId` is a strongly-typed value object
- Identity equality based on ID only
- Protected parameterless constructor for EF Core deserialization
- Private or protected constructor taking `TId id` that calls `base(id)`; create instances through static factory methods

## Aggregate Roots
- Inherit from `AggregateRoot<TId>` which extends `Entity<TId>`
- Use static factory methods for creation: `public static Order Create(TenantId tenantId, string description, ...)`
- Factories guard invariants with `ArgumentException`/`ArgumentNullException.ThrowIf...` (programmer errors only); user-input validation belongs in FluentValidation validators in Application
- Raise domain events inside factory methods and state-changing methods: `RaiseDomainEvent(new OrderCreatedEvent(...))`
- Only aggregate roots are directly persisted via repositories

## Value Objects
- Inherit from abstract `ValueObject`
- Implement `GetEqualityComponents()` returning `IEnumerable<object?>`
- Immutable: use `init` properties or readonly fields
- Examples: `OrderId`, `TenantId`, `Money`, `Address`

## Domain Events
- Inherit from `DomainEvent` abstract base class
- Named in past tense: `OrderCreatedEvent`, `PaymentProcessedEvent`
- Raised via `RaiseDomainEvent()` inside aggregate root methods
- Contain only the data needed by consumers (IDs, timestamps, key values)

## Repository Interfaces
- Defined in Domain as ports: `IOrderRepository`, `ICustomerRepository`
- Separate command repos (mutations) from query repos (reads) for CQRS
- Async signatures with CancellationToken

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.