Service (Application) Configuration
Ecotone Framework customization
Depending on the provider you choose, you can follow configuration in specific menu
Module Extensions are configurations for specific module. It's class based configuration.
Let's take a look on Dbal module configuration as example:
class MyConfiguration // 1
{
#[ServiceContext] // 2
public function registerTransactions() // 3
{
return DbalConfiguration::createWithDefaults() // 4
->withTransactionOnAsynchronousEndpoints(true)
->withTransactionOnCommandBus(true);
}
}
- 1.Create your own class. You can name it whatever you like.
- 2.Add attribute to let
Ecotone
know that it should call this method to get the configuration. - 3.Name the method whatever you like. You may return
array
of configurations orspecific configuration instance
. - 4.Return specific configuration.
Ecotone does not require specific class name or method name.
All what is needed is
#[ServiceContext]
attribute.If you want to enable different configuration for specific environment you may use of
Environment attribute
.class MyConfiguration
{
#[ServiceContext]
#[Environment(["dev", "prod"])]
public function registerTransactions()
{
return DbalConfiguration::createWithDefaults()
->withTransactionOnAsynchronousEndpoints(true)
->withTransactionOnCommandBus(true);
}
#[ServiceContext]
#[Environment(["test"])]
public function registerTransactions()
{
return DbalConfiguration::createWithDefaults()
->withTransactionOnAsynchronousEndpoints(false)
->withTransactionOnCommandBus(false);
}
}
Above will turn off transactions for
test
environment, keeping it however for prod
and dev
.You may access your configuration variables inside
ServiceContext
methods.class MyConfiguration
{
#[ServiceContext]
public function registerTransactions(#[ConfigurationVariable("database")] string $connectionDsn)
{
return Repository($connectionDsn);
}
}
If you don't pass
ConfigurationVariable
attribute, it will be taken from parameter name.
Below example is equal to above.class MyConfiguration
{
#[ServiceContext]
public function registerTransactions(string $database)
{
return Repository($database);
}
}
Last modified 9mo ago