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
to this code, which fits better to the overall usage of the container, since every other service fetching is done through class names (preferably interfaces)
useDI\FactoryInterface;
usePsr\Http\Message\ServerRequestInterfaceasRequest;
$factory = $container->get(FactoryInterface::class);
$component = $factory->make(MainComponent::class, [
Request::class => $request, // <--- the difference is here
]);
If it is not clear, the code provides/overrides a service using class name instead of parameter name.
I wonder ... why has this not been incorporated into PHP-DI container? It is very hard to replace this particular part, because the ResolverDispatcher is tightly coupled to the Container class which uses private props, and as such one would need to override half of the container class to replace it.
BTW, the same goes for the invoker, so If one desires to tweak the ResolverChain used for parameter resolution in the Container::call method, one would have to override much more than just a couple lines of code.
So my primary question is this: Is it by design that it is not possible to supply or override selected services using the type names when making calls to make or get?
I'm actually using my own autowiring solution with a simple container proxy just to overcome this shortcoming of PHP-DI container, but i may be missing something.
I made this 3 line alteration of the
ParameterResolver
in PHP-DI v6.4 (sorry, legacy project).I made the change so that I could be able to swap the following code
to this code, which fits better to the overall usage of the container, since every other service fetching is done through class names (preferably interfaces)
I wonder ... why has this not been incorporated into PHP-DI container? It is very hard to replace this particular part, because the
ResolverDispatcher
is tightly coupled to theContainer
class which usesprivate
props, and as such one would need to override half of the container class to replace it.So my primary question is this:
Is it by design that it is not possible to supply or override selected services using the type names when making calls to
make
orget
?I'm actually using my own autowiring solution with a simple container proxy just to overcome this shortcoming of PHP-DI container, but i may be missing something.
The text was updated successfully, but these errors were encountered: