yiisoft/di

Dynamic bindings

Opened this issue · 2 comments

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, pass connection2 for ConnectionInterface.
[
'parameterName' => 'secondaryConnection',
'definition' => Reference::to('connection2'),
],

It's done in #352