I have a controller action into which I would like to inject the product-repository
namespace Nosto\Tagging\Controller\Export;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Backend\App\Action;
use Magento\Framework\App\Action\Context;
class Test extends Action
{
private $_productRepository;
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
ProductRepositoryInterface $productRepository
) {
parent::__construct($context);
$this->_storeManager = $storeManager;
$this->_productRepository = $productRepository;
}
No matter what order I put my constructor arguments, Magento's dependency-injection always injects an invalid class for the productRepository
argument leading PHP to throw and argument error. The storeManager
getd injected just fine. Clearing the caches haven't helped.
Here is the exception thrown:
Recoverable Error: Argument 3 passed to Nosto\Tagging\Controller\Export\Test::__construct() must implement interface Magento\Catalog\Api\ProductRepositoryInterface, instance of Nosto\Tagging\Helper\Account given.
The class names and argument positions in the error message change but the error definition is always the same. Removing the ProductRepositoryInterface
from the constructor makes everything fine again.