PHP Classes

File: docs/guides/aem-and-ddd.md

Recommend this page to a friend!
  Packages of ?????? ???????   Adaptive Entity Manager   docs/guides/aem-and-ddd.md   Download  
File: docs/guides/aem-and-ddd.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Adaptive Entity Manager
Entity manager to work with multiple data sources
Author: By
Last change:
Date: 3 months ago
Size: 2,928 bytes
 

 

Contents

Class file image Download

AEM and DDD

Using Adaptive Entity Manager with domain-driven design ideas: value objects, persistence-ignorant domain types, and repository-oriented access?without forcing AEM contracts into the domain.

AEM does not implement full DDD tactical patterns (aggregates, domain events, sagas). It helps with mapping and persistence at the infrastructure edge.

What AEM supports well

Value objects on entities

  • Built-in ValueObjectInterface path with converters (VALUE_OBJECTS.md)
  • Domain types without AEM interfaces via metadata `class`, `from`, `to` on `value_object` fields (MVP in core v1.6+; see RFC-003)

Example metadata (infrastructure):

'email' => [
    'type' => 'value_object',
    'class' => Email::class,
    'from' => 'fromString',
    'to' => '__toString',
],

Domain stays free of Kabiroman\AEM\? imports when you use the metadata path. Runnable demo: examples/ddd_domain_vo_demo.php.

Repository-shaped access

Expose aggregate roots or use cases through interfaces; implement with AEM in infrastructure (hexagonal guide).

Legacy and uneven schemas

Map odd columns to rich types (VOs, booleans with values, etc.) while the domain model improves incrementally.

What to decide explicitly (AEM will not decide for you)

| Topic | Your choice | |-------|-------------| | Aggregate boundaries | Which roots you load/save as a consistency unit | | Reconstitution | Named constructors vs reflection hydration (AEM hydrates without calling entity constructors by default) | | Lazy loading inside aggregates | Often discouraged; AEM allows it?use deliberately | | Domain events | Outside AEM lifecycle; wire in application layer | | Cross-aggregate references | IDs vs entities; adapter and metadata design |

Future aggregate-oriented metadata (aggregateRoot, reconstitute) is roadmap only in RFC-003?not shipped in the MVP.

Anti-patterns to avoid

  • Implementing ValueObjectInterface in domain only because AEM asked for it?prefer metadata `from` / `to` when you care about pure domain.
  • Treating every entity as a public repository surface?narrow ports to roots or use cases.
  • Leaking `AdaptiveEntityManager` into domain services?keep it in infrastructure adapters.

Suggested reading order

  1. VALUE_OBJECTS.md ? configuration and examples
  2. AEM and hexagonal architecture ? ports and adapters
  3. RFC-003 ? long-term mapping direction (later phases are proposals)

Related guides