di
di copied to clipboard
Dynamic bindings
Container:
'connection' => [ ... ],
'connection2' => [ ... ],
bindings.php:
'ConnectionInterface' => [
// When namespace starts with `App\Secondary`, pass `connection2` for `ConnectionInterface`.
[
'namespace' => 'App\Secondary',
'definition' => Reference::to('connection2'),
],
// When parameter name is `secondaryConnection`, pass `connection2` for `ConnectionInterface`.
[
'parameterName' => 'secondaryConnection',
'definition' => Reference::to('connection2'),
],
],
Using this feature may degrade overall container performance.
// When parameter name is
secondaryConnection, passconnection2forConnectionInterface. [ 'parameterName' => 'secondaryConnection', 'definition' => Reference::to('connection2'), ],
It's done in #352