Skip to content

DDD Principles

Daniel Mackay [SSW] edited this page Apr 30, 2023 · 1 revision

Aggregate Roots

  • Use AggregateRoots for objects that can be created directly
  • All user interactions should go via AggregateRoots
  • Exposed via DbContext
  • Will have a table in t
  • Aggregates can only be pulled in their entirety from the DB. This means that all child entities that make up the aggregate root will also be pulled in

Entities

  • Use Entities for objects that are part of an aggregate root and distinguishable by ID (usually a separate table)
  • Entities cannot be modified outside of their aggregate root
  • Not exposed via DbContext
  • Will have a table in the DB
  • Internal factory method for creation so that can only be created via aggregate roots
  • Behaviors should be internal so that they can only be called by the aggregate root

Value Objects

  • Use ValueObjects for objects that are defined by their properties (i.e. not by ID) (usually part of another table)
  • Value objects can only be modified as part of their aggregate root
  • Will be part of the AggregateRoot table in the DB
  • Configured in EF via builder.OwnsOne()

General

  • objects can be created using
    • factory methods
  • All properties should be readonly (i.e. private)
Clone this wiki locally