We can use Ecotone's Symfony integration to reuse Connections that are already defined in your Symfony Application.
Suppose we already defined connection in our "doctrine.yaml" file:
doctrine:
dbal:
connections:
some_connection:
url: '%env(resolve:DATABASE_DSN)%'
Then to use it as our Default Connection, we can use Service Context config:
final readonly class EcotoneConfiguration
{
#[ServiceContext]
public function dbalConfiguration()
{
return SymfonyConnectionReference::defaultConnection('some_connection');
}
}
{% hint style="success" %} It's all we need to configure. Ecotone will now know to use some_connection as default. {% endhint %}
Configuring Dbal Module with Manager Registry allows to make your Entities work as a Ecotone's Aggregates.
Suppose we already defined connection in our "doctrine.yaml" file:
doctrine:
dbal:
default_connection: tenant_a_connection
connections:
some_connection:
url: '%env(resolve:DATABASE_DSN)%'
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
some_orm_connection:
connection: some_connection
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src'
prefix: 'App'
Then to use it as our Default Connection, we can use Service Context config:
final readonly class EcotoneConfiguration
{
#[ServiceContext]
public function dbalConfiguration()
{
return SymfonyConnectionReference::defaultManagerRegistry('some_connection');
}
}
{% hint style="success" %} It's all we need to configure. Ecotone will now know to use some_orm_connection as default. {% endhint %}
If we don't have existing connection defined, we can make use of DSN directly
Enqueue\Dbal\DbalConnectionFactory:
class: Enqueue\Dbal\DbalConnectionFactory
factory: ["Ecotone\Dbal\DbalConnection", "fromDsn"]
arguments: ["pgsql://user:password@host:5432/db_name"]