You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is something like this at all possible without creating the instance manually e.g. new $class( ... and having to manually build all the instance dependencies when I just need to dynamically define one?
The example definitions below would of course return an instance of the AutowireDefinitionHelper and not the real class instance.
Imagine later we call $container->get( My\Namespace\Fun\Things\Controller ); I'd like to tell PHP-DI that when the controller needs a concrete of say, DifferentClassInterface, that it would inject My\Namespace\Fun\Things\DifferentClass.
Example definitions:
return [
'My\Namespace\*\*\Controller' => staticfunction( DI\Factory\RequestedEntry$r ): ControllerInterface {
$customDepdendency = DI\create( 'My\Namespace\*\*\DifferentClass' );
// or? $customDepdendency = DI\get( 'My\Namespace\*\*\DifferentClass' );$class = $r->getName();
// Imagine $class has 4 or 5 dependencies that can be resolved via autowiringreturnDI\autowire( $class )->constructorParameter( 'customDepdendency', $customDepdendency );
},
];
The text was updated successfully, but these errors were encountered:
It seems like you have a certain 1:1 mapping from a X\Controller requiring the proper X\DifferentClass. Unless you can provider a better explanation of why you'd want what you want, I'd suggest that simply requiring X\DifferentClass as a controller constructor parameter will easily be autowired out of the box.
Is something like this at all possible without creating the instance manually e.g.
new $class( ...
and having to manually build all the instance dependencies when I just need to dynamically define one?The example definitions below would of course return an instance of the
AutowireDefinitionHelper
and not the real class instance.Imagine later we call
$container->get( My\Namespace\Fun\Things\Controller );
I'd like to tell PHP-DI that when the controller needs a concrete of say,DifferentClassInterface
, that it would injectMy\Namespace\Fun\Things\DifferentClass
.Example definitions:
The text was updated successfully, but these errors were encountered: