Answer the question
In order to leave comments, you need to log in
Why doesn't Dependency Injection work in Magento 2?
Added a helper class for working with products, the constructor looks like this:
public function __construct(\Magento\Catalog\Model\ProductRepository $repository = null)
{
$this->_repository = $repository ?: $this->_objectManager->create('\Magento\Catalog\Model\ProductRepository');
}
Answer the question
In order to leave comments, you need to log in
Here is an example of a simple injection:
https://www.mageplaza.com/blog/the-basics-of-depen...
I made the Data and HelperDemo classes following the example, the injection does not work, writes:
"ArgumentCountError: Too few arguments to function DependentClass ::__construct(), 0 passed...."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question