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
public function getDbalConfiguration(): DbalConfiguration
return DbalConfiguration::createWithDefaults()


Then you mark your Entities with Aggregate attribute and set up Command Handlers.
class User
use WithEvents;
private string $userId;
private string $name;
private bool $isActive;
private function __construct(string $userId, string $name)
$this->userId = $userId;
$this->name = $name;
$this->isActive = false;
$this-recordThat(new UserRegistered($userId)); // 3. Event Publishing
#[CommandHandler] // 1. Factory method register
public static function register(RegisterUser $command): static
return new static(Uuid::uuid4()->toString(), $command->name);
#[CommandHandler("activate")] // 2. Action method "activate"
public function activate(): void
$this->isActive = true;
  1. 1.
    Calling factory method "register":
$this->commandBus->send(new RegisterUser('Johny'));
  1. 2.
    Calling action method "activate":
$this->commandBus->sendWithRouting("activate", metadata: ["" => $id]);
  1. 3.
    By importing trait WithEvents we can publish events from our Aggregate using recordThat method.
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.


Read more about integration in following blog post.