-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
There was a problem hiding this 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?
@prolic Yes that's it, the default one like in documentation or example and a custom one. By default it will retrieve the |
$eventStore = $container->get(EventStore::class); | ||
$eventStoreClass = $config['event_store_class'] ?? EventStore::class; | ||
|
||
$eventStore = $container->get($eventStoreClass); |
There was a problem hiding this comment.
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']);
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed.
LGTM. 👍 @Orkin Please run |
There was a problem hiding this 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?
@prolic it is ok for you like this ? |
Thanks @Orkin |
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