ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 17 - AD0-E722 discussion

Report
Export

While developing a new functionality for a website in developer mode with all cache types enabled, an Adobe Commerce Developer needs to add \Magento\Sales\Model\Service\InvoiceService SinvoiceService as a new dependency to an existing page action controller in Vendor\CustomModule\Controller\Index\Index . This is accomplished as follows:

After cleaning the f ull_page cache and reloading the page, the developer encounters the following exception:

Recoverable Error: Argument 2 passed to Vendor\CustomModule\Controller\Index\Index::__construct() must be an instance of

\Magento\Sales\Model\Service\InvoiceService [...]

Which action should the Architect recommend to the developer to fix this error?

A.
Clean the block_html cache along with full_page cache.
Answers
A.
Clean the block_html cache along with full_page cache.
B.
Add the new \Magento\sales\Model\service\invoiceService Sinvoiceservice dependency at the end of the constructor signature.
Answers
B.
Add the new \Magento\sales\Model\service\invoiceService Sinvoiceservice dependency at the end of the constructor signature.
C.
Remove the generated Child ClaSS from generated/code/Vendor/CustomModule/Controller/Index/Index.
Answers
C.
Remove the generated Child ClaSS from generated/code/Vendor/CustomModule/Controller/Index/Index.
Suggested answer: C

Explanation:

The error is caused by the generated child class not being updated with the new dependency. Removing the generated child class will allow the system to generate a new child class with the correct dependency. The generated child class is a proxy class that extends the original controller class and overrides the constructor to inject the dependencies using the object manager. The generated child class is created when the system runs in developer mode with cache enabled, to avoid performance issues. However, when a new dependency is added to the original controller class, the generated child class does not reflect the change and causes a mismatch in the constructor arguments. Therefore, deleting the generated child class from the generated/code directory will solve the problem.

Generated code | Adobe Commerce Developer Guide

Constructor signature change | Adobe Commerce Developer Guide

asked 02/10/2024
Ghazi Khan
24 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first