Issue Bug Closed

#77828Inversion of Control is not working in controller action arguments

Dennis Römmich 09/03/16, 12:39 updated 02/04/18, 15:47

Description

If you register an Implementation like extbase does in typo3/sysext/extbase/ext_localconf.php:9 it won’t be considered if the given interface ist passed as an action controller argument.

Example:
1. Register an implementation in your ext_localconf.php

/** @var $extbaseObjectContainer \TYPO3\CMS\Extbase\Object\Container\Container */
$extbaseObjectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
$extbaseObjectContainer->registerImplementation(\MyVendor\MyExtension\MyInterface::class, \MyVendor\MyExtension\Domain\Model\MyClass::class);

2. Create a simple Action in your ActionController with passig MyInterface as TypeHint:

    /**
     * showAction
     *
     * @param \MyVendor\MyExtension\MyInterface $myClass
     * @return void
     */
    public function showAction(\MyVendor\MyExtension\MyInterface $myClass)
    {
        //do some stuff
    }

It will lead to an Exception:

#1297759968: Exception while property mapping at property path "": No converter found which can be used to convert from "string" to "\MyVendor\MyExtension\MyInterface".

Reviews 2