Bug #97149
closedGeneralUtility::makeinstance() container fetch should be allowed with or without arguments.
0%
Description
Currently if a service has arguments, fetching it from the container is disallowed even though in nearly all cases the container already holds an instance of the service or is ready to create one complete with autowiring.
The current approach is inefficient since one loses all autowiring benefits ...and kinda nuts because every service created using GeneralUtility::makeinstance() with arguments never benefits from DI.
So, instead of having this line in the method with the arguments prohibition in GeneralUtility::makeinstance():
if(self::$container!==null && $constructorArguments===[] && self::$container->has($className)){
return self::$container->get($className);
}
let's have this following instead so we can squeeze all the juice out of having Symphony's DI:
if(self::$container!==null && self::$container->has($className)){
$instance=self::$container->get($className);
if($constructorArguments){
return $instance(...$constructorArguments);
}
return $instance;
}
I've autowired a custom route aspect mapper. It is called by GeneralUtility::makeinstance() from AspectFactory
through the PageResolver
middleware, and because it has settings
argument (as it should) in its constructor, fetching it from the DI is skipped. The truth is, it doesn't have to be. I believe you'll agree that this change is all benefit and no pain.