✅ 1. Domain Events
Domain events model things that happen inside the domain and allow other parts of the system to react.
Use cases
- Send email after order placed
- Reduce inventory
- Publish message to message bus
- Update read models
Domain Event Example
Aggregate raising event
Domain Event Handler
✅ 2. Ubiquitous Language
It means:
Everyone (developers, business, testers, PMs) uses the SAME terms with SAME meaning.
Example:
Business says Order → OrderItem → Payment → Customer
So your code should also use Order, not “Tbl_Order”.
Bad example:
-
Business says “Order”
-
Code says “PurchaseTransactionRecord”
Good example:
This maintains clarity and reduces misunderstandings.
✅ 3. Bounded Context
A bounded context defines a logical boundary within which a domain model is consistent.
Example:
In an E-commerce system:
| Bounded Context | Meaning of “Order” |
|---|---|
| Ordering BC | Order = items customer wants |
| Billing BC | Order = financial transaction |
| Shipping BC | Order = package to be shipped |
Each BC has its own:
- Model
- Database
- Services
- Ubiquitous language
C# Example
Different BCs have different Order definitions:
Ordering BC
Shipping BC
✅ 4. DTO (Data Transfer Object)
DTOs are simple objects used to transfer data across boundaries (API layer ↔ Application layer).
Not used for business logic.
Example
Controller returning DTO instead of domain entity
✅ 5. Aggregate
Aggregate = cluster of domain objects treated as a single unit
Aggregate Root = main entry point, enforces invariants.
Example
Order (root) → contains OrderItems (child entities)
Child entity:
Rules:
- Only aggregate root is loaded from repository.
- Only aggregate root is saved.
- External code cannot modify inner entities directly.
✅ 6. Value Object
Value objects:
-
Immutable
-
Compared by values (not identity)
-
No Id
-
Represent concepts like Money, Email, Address, Quantity
C# Example
Usage:
✅ 7. Rich Model vs Anemic Model
Anemic Model (Anti-pattern)
- Entities only have properties
- Logic sits outside in service classes
- Looks like a database table
- Easy but poor domain modeling
Example:
Business logic in services:
Rich Domain Model (Recommended in DDD)
Business logic lives inside domain entities.
Example:
Rich model:
- Enforces business rules
- Reduces duplication
- Maintains invariants
🎯 Summary Table
| Concept | One-line definition |
|---|---|
| Repository | Abstraction over data access for aggregates |
| Domain Events | Things that happened in the domain |
| Ubiquitous Language | Same terms used across business & code |
| Bounded Context | Clear boundary where a domain model is consistent |
| DTO | Data-only object for transferring data |
| Aggregate | Cluster of domain objects with rules |
| Value Object | Immutable concept compared by value |
| Rich Model | Entities with behavior (preferred in DDD) |
| Anemic Model | Entities with only properties (anti-pattern) |