Skip to content

Commit a9e3edc

Browse files
committed
Add PSR container
1 parent df672fc commit a9e3edc

18 files changed

Lines changed: 2630 additions & 272 deletions

docs/getting-started.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,9 @@ If you use symfony, you can use our [symfony bundle](/docs/event-sourcing-bundle
271271
```php
272272
use Doctrine\DBAL\DriverManager;
273273
use Doctrine\DBAL\Tools\DsnParser;
274-
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
275-
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
276-
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
277-
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
278-
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
279-
use Patchlevel\EventSourcing\Subscription\Engine\StoreMessageLoader;
280-
use Patchlevel\EventSourcing\Subscription\Repository\RunSubscriptionEngineRepositoryManager;
281-
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
282-
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
283-
284-
$connection = DriverManager::getConnection(
285-
(new DsnParser())->parse('pdo-pgsql://user:secret@localhost/app'),
286-
);
274+
use Patchlevel\EventSourcing\Container\Configuration;
275+
use Patchlevel\EventSourcing\Container\Factory;
276+
use Patchlevel\EventSourcing\Repository\RepositoryManager;
287277

288278
$projectionConnection = DriverManager::getConnection(
289279
(new DsnParser())->parse('pdo-pgsql://user:secret@localhost/projection'),
@@ -292,38 +282,18 @@ $projectionConnection = DriverManager::getConnection(
292282
/* your own mailer */
293283
$mailer;
294284

295-
$serializer = DefaultEventSerializer::createFromPaths(['src/Domain/Hotel/Event']);
296-
$aggregateRegistry = (new AttributeAggregateRootRegistryFactory())->create(['src/Domain/Hotel']);
297-
298-
$eventStore = new DoctrineDbalStore(
299-
$connection,
300-
$serializer,
301-
);
302-
303-
$hotelProjector = new HotelProjector($projectionConnection);
304-
305-
$subscriberRepository = new MetadataSubscriberAccessorRepository([
306-
$hotelProjector,
307-
new SendCheckInEmailProcessor($mailer),
308-
]);
309-
310-
$subscriptionStore = new DoctrineSubscriptionStore($connection);
311-
312-
$engine = new DefaultSubscriptionEngine(
313-
new StoreMessageLoader($eventStore),
314-
$subscriptionStore,
315-
$subscriberRepository,
316-
);
317-
318-
$repositoryManager = new RunSubscriptionEngineRepositoryManager(
319-
new DefaultRepositoryManager(
320-
$aggregateRegistry,
321-
$eventStore,
322-
),
323-
$engine,
324-
);
325-
326-
$hotelRepository = $repositoryManager->get(Hotel::class);
285+
$configuration = Configuration::createWithConnectionUrl('pdo-pgsql://user:secret@localhost/app')
286+
->withDefaultSettings(
287+
['src/Domain/Hotel'],
288+
['src/Domain/Hotel/Event'],
289+
)
290+
->withSubscribers([
291+
new HotelProjector($projectionConnection),
292+
new SendCheckInEmailProcessor($mailer)
293+
]);
294+
$container = Factory::create($configuration);
295+
296+
$hotelRepository = $container->get(RepositoryManager::class)->get(Hotel::class);
327297
```
328298
:::note
329299
You can find out more about stores [here](store.md).

0 commit comments

Comments
 (0)