Persistence Strategy
PHP Event Sourcing Persistence Strategy
Persistence Strategy
Describes how streams with events will be stored.
Single Stream Strategy
The default persistence strategy is the Single Stream Strategy. This persistence stores all instances of specific aggregate, within the same stream.
All instances of Ticket
will be stored within Domain\Ticket\Ticket stream
.
Read more about this strategy under SingleStreamStrategy
:
http://docs.getprooph.org/event-store/implementations/pdo_event_store/variants.html#SingleStreamStrategy
Stream Per Aggregate Strategy
This persistence creates a stream per aggregate instance.
Instances of Ticket
will be stored within Domain\Ticket\Ticket-{ticketId} stream
where ticketId
is an identifier of a specific aggregate.
Read more about this strategy under AggregateStreamStrategy
:
http://docs.getprooph.org/event-store/implementations/pdo_event_store/variants.html#AggregateStreamStrategy
Custom Strategy
You may provide your own Customer Persistence Strategy as long as it implements PersistenceStrategy
.
Multiple Persistence Strategies
Once set, the persistence strategy will apply to all streams in your application. However, you may face a situation when you need to have a different strategy for one or more of your streams.
The above will make the Simple Stream Strategy as default however, for some_stream
Event Store will use the Aggregate Stream Strategy.
Please, be aware that you won't be able to set Custom Strategy that way.
Custom Stream Name
If you want to make use of a custom stream name (the default is Aggregate class name), then you can apply Stream
attribute to your aggregate.
Then tell the projection to make use of it:
Custom Aggregate Type
By default events in the stream will hold Aggregate Class name as AggregateType
.
You may customize this by applying AggregateType
attribute to your Aggregate.
Setting this up will allow you to refactor the aggregate class name or namespace and still load the same Aggregate.
Last updated