yiisoft / di

PSR-11 compatible DI container and injector
https://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
182 stars 45 forks source link

Dynamic bindings #330

Open samdark opened 1 year ago

samdark commented 1 year ago

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'),
  ],
],
samdark commented 1 year ago

Using this feature may degrade overall container performance.

xepozz commented 9 months ago

// When parameter name is secondaryConnection, pass connection2 for ConnectionInterface. [ 'parameterName' => 'secondaryConnection', 'definition' => Reference::to('connection2'), ],

It's done in #352