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

Allow to add a custom event store to AggregateRepository #76

Merged
merged 5 commits into from
Apr 30, 2018

Conversation

Orkin
Copy link
Contributor

@Orkin Orkin commented Apr 29, 2018

It can be really useful when the one_stream_per_aggregate config is set to true. Real event stream table is automatically create on save and for one of my use case I have a different format for aggregate_id (concatenation of 2 uuid separate by _) so the column length will become 73 instead of 36. I have my own stream strategy but only for one stream so when I configure my aggregate_repository I need to inject my custom event store

@coveralls
Copy link

coveralls commented Apr 29, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 09826ff on Orkin:allow-add-custom-event-store into 67fa365 on prooph:master.

Copy link
Member

@prolic prolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you have two event store instances in your app, correct?

@Orkin
Copy link
Contributor Author

Orkin commented Apr 30, 2018

@prolic Yes that's it, the default one like in documentation or example and a custom one. By default it will retrieve the EventStore::class from the container.

$eventStore = $container->get(EventStore::class);
$eventStoreClass = $config['event_store_class'] ?? EventStore::class;

$eventStore = $container->get($eventStoreClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to: $eventStore = $container->get($config['event_store']);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, implement ProvidesDefaultConfig and add EventStore::class as default option to event_store.


$eventStore = $container->get($eventStoreClass);

if (! $eventStore instanceof EventStore) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, as the aggregate repository already has a typehint for this, so we'll catch that exception already.

@@ -81,7 +81,13 @@ public function __invoke(ContainerInterface $container): AggregateRepository
throw ConfigurationException::configurationError(sprintf('Repository class %s must be a sub class of %s', $repositoryClass, AggregateRepository::class));
}

$eventStore = $container->get(EventStore::class);
$eventStoreClass = $config['event_store_class'] ?? EventStore::class;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed.

@sandrokeil
Copy link
Member

LGTM. 👍 @Orkin Please run composer cs-fix.

Copy link
Member

@prolic prolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Can you update the docs and explain how to use it?

@Orkin
Copy link
Contributor Author

Orkin commented Apr 30, 2018

@prolic it is ok for you like this ?

@prolic prolic merged commit 624810e into prooph:master Apr 30, 2018
@prolic
Copy link
Member

prolic commented Apr 30, 2018

Thanks @Orkin

@prolic
Copy link
Member

prolic commented Apr 30, 2018

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

Successfully merging this pull request may close these issues.

4 participants