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.
#[Aggregate]
class User
{
use WithEvents;
#[AggregateIdentifier]
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;
}
}
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.
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.
final readonly class EcotoneConfiguration
{
#[ServiceContext]
public function dbalConfiguration()
{
return DbalConfiguration::createWithDefaults()
->withClearAndFlushObjectManagerOnCommandBus(false)
->withClearAndFlushObjectManagerOnAsynchronousEndpoints(false);
}
}
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: