-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPartServiceProvider.php
executable file
·94 lines (79 loc) · 3.02 KB
/
PartServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php namespace Modules\Parts;
use Illuminate\Support\ServiceProvider;
use Modules\Parts\Commands\Handlers\PartCommandHandler;
use Modules\Parts\Console\ReplayPartsCommand;
use Modules\Parts\ReadModel\PartsThatWereManufacturedProjector;
use Modules\Parts\Repositories\ElasticSearchReadModelPartRepository;
use Modules\Parts\Repositories\MysqlEventStorePartRepository;
class PartServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
* @return void
*/
public function register()
{
$this->bindEventSourcedRepositories();
$this->bindReadModelRepositories();
$this->registerCommandSubscribers();
$this->registerEventSubscribers();
$this->registerConsoleCommands();
include_once __DIR__.'/Http/routes.php';
}
public function boot()
{
$this->app['view']->addNamespace('parts', __DIR__.'/resources/views');
}
/**
* Bind repositories
*/
private function bindEventSourcedRepositories()
{
$this->app->bind('Modules\Parts\Repositories\EventStorePartRepository', function ($app) {
$eventStore = $app['Broadway\EventStore\EventStoreInterface'];
$eventBus = $app['Broadway\EventHandling\EventBusInterface'];
return new MysqlEventStorePartRepository($eventStore, $eventBus, $app['Doctrine\DBAL\Connection']);
});
}
/**
* Bind the read model repositories in the IoC container
*/
private function bindReadModelRepositories()
{
$this->app->bind('Modules\Parts\Repositories\ReadModelPartRepository', function ($app) {
$serializer = $app['Broadway\Serializer\SerializerInterface'];
return new ElasticSearchReadModelPartRepository($app['Elasticsearch'], $serializer);
});
}
/**
* Register the command handlers on the command bus
*/
private function registerCommandSubscribers()
{
$partCommandHandler = new PartCommandHandler($this->app['Modules\Parts\Repositories\EventStorePartRepository']);
$this->app['laravelbroadway.command.registry']->subscribe([
$partCommandHandler
]);
}
/**
* Register the event listeners on the event bus
*/
private function registerEventSubscribers()
{
$partsThatWereManfacturedProjector = new PartsThatWereManufacturedProjector($this->app['Modules\Parts\Repositories\ReadModelPartRepository']);
$this->app['laravelbroadway.event.registry']->subscribe([
$partsThatWereManfacturedProjector
]);
}
private function registerConsoleCommands()
{
$this->app->bindShared('command.asgard.replay.parts', function ($app) {
$eventStorePartRepository = $app['Modules\Parts\Repositories\EventStorePartRepository'];
$eventBus = $app['Broadway\EventHandling\EventBusInterface'];
return new ReplayPartsCommand($eventStorePartRepository, $eventBus);
});
$this->commands([
'command.asgard.replay.parts',
]);
}
}