Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a CommandHandler #1

Open
josecelano opened this issue Jan 9, 2015 · 3 comments
Open

Using a CommandHandler #1

josecelano opened this issue Jan 9, 2015 · 3 comments

Comments

@josecelano
Copy link

In your controller:

https://github.com/tyx/ddd-sample-symfony/blob/master/src/BookingEngine/UI/Controller/BookingController.php#L50

        $form->handleRequest($request);
        if (!$form->isValid()) {
            throw new HttpException(406, (string) new FormErrorsRepresentation($form->getErrors()));
        }
        try {
            // Send the message
            $this->bookingService->payBooking($command);

You use a service and pass a command as parameter.

This other Symfony DDD exmaple uses a CommandHandler:

https://github.com/leopro/trip-planner/blob/master/src/Leopro/TripPlanner/PresentationBundle/Controller/ApiController.php#L27

        $form->handleRequest($request);
        if ($form->isValid()) {
            $trip = $this->get('command_handler')->execute($form->getData());
            return new Response('ok');
        }

In that sample payBooking would use a Use Case.

Prons:

  • Common logic in Command execution as validation and event dispatcher.
  • Avoid fat services, your bookingService would be replace with some UseCase classes.

This other sample uses commandBus instead of CommandHandler:

https://github.com/tyx/cqrs-php-sandbox/blob/master/src/Afsy/UI/Controller/GameCommandController.php

I am trying to figure out which is the best option to implement DDD in a project with Symfony. Perpahs a mixing of them or it depends on the domain. What do you think?

@josecelano josecelano changed the title Use a CommandHandler Using a CommandHandler Jan 9, 2015
@tyx
Copy link
Owner

tyx commented Jan 12, 2015

Hi Jose !

I'm of course in favor of using Command Bus!
I just wanted to show that we are not required to use a real command bus class to start using Command Pattern. And it is more important to use a concept that the implementation of this concept ;)

In order to move some legacy code, it could make sense sometimes to not follow full recommendations as the goal is to simplify the comprehension and the reading of your legacy code.

But for a new project or a project with dedicated time to improve, I would add a real commandbus of course.

Avoid fat services, your bookingService would be replace with some UseCase classes.

But I disagree with this part. BookingService is an application service not a domain service. No problem to make it fat. I prefer big application service that make sense for a big Bounded Context, that many and many Command Handler class, totally separate. That help to think in Bounded Context IMO.

Again, we are talking about details, the main move here is to move to the Command Pattern, whatever the way to get there.

Hope it helps.

@josecelano
Copy link
Author

Thanks Timothée.

I am trying to find the best way to implement a MessageBus in Symfony 2. I have found these two repositories:

https://github.com/SimpleBus
https://github.com/beberlei/litecqrs-php#litecqrs-for-php

I would like to find an Symfony example application with one of them.

@tyx
Copy link
Owner

tyx commented Jan 13, 2015

I use litecqrs on my other sandbox : https://github.com/tyx/cqrs-php-sandbox/blob/master/src/Afsy/UI/SymfonyBundle/Resources/config/commands.yml

For now, it is the best I see, but Benjamin is no more very active on it : (

I don't give a try to the other ones that pop the last monthes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants