Created
November 20, 2016 12:38
-
-
Save JavierCane/952230458f04d5450ab137ef8264c370 to your computer and use it in GitHub Desktop.
Example of CQRS & DDD Application Service. Entire repo: https://github.com/CodelyTV/cqrs-ddd-example/blob/master/src/Context/Meetup/Module/Video/Domain/Create/VideoCreator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CodelyTv\Context\Meetup\Module\Video\Domain\Create; | |
use CodelyTv\Context\Meetup\Module\Video\Domain\Video; | |
use CodelyTv\Context\Meetup\Module\Video\Domain\VideoId; | |
use CodelyTv\Context\Meetup\Module\Video\Domain\VideoRepository; | |
use CodelyTv\Context\Meetup\Module\Video\Domain\VideoTitle; | |
use CodelyTv\Context\Meetup\Module\Video\Domain\VideoUrl; | |
use CodelyTv\Infrastructure\Bus\Event\DomainEventPublisher; | |
use CodelyTv\Shared\Domain\CourseId; | |
final class VideoCreator | |
{ | |
private $repository; | |
private $publisher; | |
public function __construct(VideoRepository $repository, DomainEventPublisher $publisher) | |
{ | |
$this->repository = $repository; | |
$this->publisher = $publisher; | |
} | |
public function create(VideoId $id, VideoTitle $title, VideoUrl $url, CourseId $courseId) | |
{ | |
$video = Video::create($id, $title, $url, $courseId); | |
$this->repository->save($video); | |
$this->publisher->publish($video->pullDomainEvents()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment