Skip to content
Permalink
Browse files

Version25

Adding command bus and separate out command handling from domain.

I opted for <a href="https://github.com/SimpleBus"
target="_blank">SimpleBus</a> because I liked the simplicity and have a lot of
respect for it's maintainer Mathias.

I did have <a href="SimpleBus/CommandBus#2"
target="_blank">some misgivings over the use of a type hint for
commands</a>, but
generally it suited what I needed to do well, it also forced me to
create an explicit CommandHandling layer, which I think works quite
well. It's been completely changed in version 2 now anyway, and is <a
href="https://github.com/SimpleBus/MessageBus" target="_blank">more
of a generic 'MessageBus' now</a>.

There are quite a few command buses that have popped up recently, I
created <a href="https://github.com/jenkoian/CommandBusCommandBus"
target="_blank">CommandBusCommandBus</a> as a case in point. Anyway the
point is I wanted to introduce a command bus to make my example
complete.

Here you can see how I've moved all the command handling bits to the
CommandHandling later I spoke about above. It just means that rather
than passing command to handlers directly, I can just 'throw' them on to
the command bus now. This has the advantages of being able to decorate
the command bus to be able to perform additional tasks against commands
should I want to; I can make the command bus handle commands
asynchronously should I choose; plus other niceities that arise when
delegating message handling in this way.
  • Loading branch information
jenkoian committed Jan 20, 2015
1 parent 4fdc5ed commit a9ca03a9d882cf03d1e8ca48f17f9780a62ec1f5
@@ -16,6 +16,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle(),

// House Bundles
new Jenko\HouseBundle\JenkoHouseBundle(),
@@ -18,7 +18,8 @@
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"phpspec/phpspec": "~2.0@RC"
"phpspec/phpspec": "~2.0@RC",
"simple-bus/symfony-bridge": "~1.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3",

Some generated files are not rendered by default. Learn more.

@@ -1,10 +1,10 @@
<?php

namespace spec\Jenko\House\Handler;
namespace spec\Jenko\HouseCommandHandlingHandler;

use Jenko\House\Command\EnterRoomCommand;
use Jenko\House\Event\EventDispatcherInterface;
use Jenko\House\Factory\HomeAloneHouseFactory;
use Jenko\HouseCommandHandling\Command\EnterRoomCommand;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

@@ -17,7 +17,7 @@ function let(EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Handler\EnterRoomHandler');
$this->shouldHaveType('Jenko\HouseCommandHandling\Handler\EnterRoomHandler');
}

function it_dispatches_events(EventDispatcherInterface $dispatcher)
@@ -1,8 +1,8 @@
<?php

namespace spec\Jenko\House\Handler;
namespace spec\Jenko\HouseCommandHandling\Handler;

use Jenko\House\Command\ExitRoomCommand;
use Jenko\HouseCommandHandling\Command\ExitRoomCommand;
use Jenko\House\Event\EventDispatcherInterface;
use Jenko\House\Factory\HomeAloneHouseFactory;
use PhpSpec\ObjectBehavior;
@@ -17,7 +17,7 @@ function let(EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Handler\ExitRoomHandler');
$this->shouldHaveType('Jenko\HouseCommandHandling\Handler\ExitRoomHandler');
}

function it_dispatches_events(EventDispatcherInterface $dispatcher)

This file was deleted.

0 comments on commit a9ca03a

Please sign in to comment.
You can’t perform that action at this time.