No Invariant, Two Aggregates

We'll discuss Application Services in the following chapters, but for now, let's check different approaches for making a Wish. The first approach, particularly for a novice, would likely be something similar to this:

class MakeWishService{    private $wishRepository;    public function __construct(WishRepository $wishRepository)    {        $this->wishRepository = $wishRepository;    }    public function execute(MakeWishRequest $request)    {        $userId = $request->userId();        $address = $request->address();        $content = $request->content();        $wish = new Wish(            $this->wishRepository->nextIdentity(),            new UserId($userId),            $address,            $content        );        $this->wishRepository->add($wish);    }}

This code probably allows for the best performance possible. You ...

Get Domain-Driven Design in PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.