Doctrine ORM
Ecotone comes with out of the box Doctrine ORM support for Aggregates.
Enable Doctrine ORM
First install Dbal Module with Manager Registry Connection.
class EcotoneConfiguration
{
#[ServiceContext]
public function getDbalConfiguration(): DbalConfiguration
{
return DbalConfiguration::createWithDefaults()
->withDoctrineORMRepositories(true);
}
# Configuration from Manager Registry Connection
#[ServiceContext]
public function getManagerRegistryConfiguration()
{
return SymfonyConnectionReference::defaultManagerRegistry('some_connection');
}
}Example
Then you mark your Entities with Aggregate attribute and set up Command Handlers.
Calling factory method "register":
Calling action method "activate":
By importing trait
WithEventswe can publish events from our Aggregate usingrecordThatmethod.
In case of Ecotone you may use routing for your Message Handlers or direct Message Classes. It's up to you to decide whatever works best in your context.
Flushing Doctrine ORM Changes
Ecotone will take care of object flush and clearing your object manager. This way we don't need to bother about integration part of the code. If you want take over the process this can be disabled via DbalConfiguration.
Auto-Incremented Identifier
When using Doctrine ORM with auto incremented identifiers like sequences, identifier is not available from the beginning, yet it's assigned at later stage by Doctrine ORM itself. Ecotone works with auto-incremental identifiers, yet they must be initialized with null to state that:
Enable Repository for given Aggregates
To enable Doctrine ORM for given set of Aggregates use DbalConfiguration:
Demo
Read more about integration in following blog post.
Last updated
Was this helpful?