Repositories Introduction
Repository PHP
Last updated
Was this helpful?
Repository PHP
Last updated
Was this helpful?
Read sections first to get more details about Aggregates.
Repositories are used for retrieving and saving the aggregate to persistent storage. Typical flow for calling aggregate method would looks like below:
By setting up Repository
we provide Ecotone with functionality to fetch and store the Aggregate , so we don't need to do it on our own.
If our class is defined as Aggregate, Ecotone will use Repository in order fetch and store it, whenever the Command
is sent via Command Bus
.
Based on which interface is implemented, Ecotone
knows which Aggregate type was selected.
State-Stored Aggregate are normal Aggregates
, which are not Event Sourced
.
canHandle method
informs, which Aggregate Classes
can be handled with this Repository
. Return true, if saving specific aggregate is possible, false otherwise.
findBy method
returns if found, existing Aggregate instance
, otherwise null.
save method
is responsible for storing given Aggregate instance
.
$identifiers
are array of #[Identifier]
defined within aggregate.
$aggregate
is instance of aggregate
$metadata
is array of extra information, that can be passed with Command
$expectedVersion
if version locking by #[Version]
is enabled it will carry currently expected
When your implementation is ready simply mark it with #[Repository]
attribute:
This is example implementation of Standard Repository using Doctrine ORM.
Repository:
When your implementation is ready simply mark it with #[Repository]
attribute:
Ecotone provides inbuilt repositories to get you started quicker. This way you can enable given repository and start implementing higher level code without worrying about infrastructure part.
By default Ecotone when we have only one Standard and Event Sourcing Repository registered, Ecotone will use them for our Aggregate by default. This comes from simplification, as if there is only one Repository of given type, then there is nothing else to be choose from. However, if we register multiple Repositories, then we need to take over the process and tell which Repository will be used for which Aggregate.
In case of inbuilt Repositories, we should follow configuration section for given type
There are two types of repositories. One for storing and another one for storing .
This provides integration with . To enable it read more in .
This provides integration with . Eloquent support is available out of the box after installing .
This provides integration using relational databases. It will serialize your aggregate to json and deserialize on load using . To enable it read in .
Ecotone provides inbuilt Event Sourcing Repository, which will set up Event Store and Event Streams. To enable it read .
In case of we do it using canHandle method.
Custom repository for Event Sourced Aggregates is described in more details under .