Enable WebAPI interface to handle parameters through constructor#14801
Conversation
DTO setter methods are no more required, parameters can be handled through constructor for immutable state approach A setter fallback is supported
_createFromArray will not be fixed due to its eventual deprecation, since a new immutable approach is provided
…m:phoenix128/magento2 into webapi-support-immutable-construct-params
| AttributeValueFactory $attributeValueFactory, | ||
| CustomAttributeTypeLocatorInterface $customAttributeTypeLocator, | ||
| MethodsMap $methodsMap, | ||
| \Magento\Framework\ObjectManager\ConfigInterface $config, |
There was a problem hiding this comment.
Hi, @phoenix128 , due to Magento backward-compatible guide we can't add required parament to the constructor.
Please add the optional parameter and take instance from ObjectManager, as example:
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()>get(\Magento\Store\Model\StoreManagerInterface::class);
|
Hi @phoenix128 , any updates? |
|
Hi @VladimirZaets , sorry if I did not answer you before. I've been terribly busy. You are definitely right about that, I must have forgotten it while coding quickly. Fixing in the next commit. |
Enable WebAPI interface to handle parameters through constructor magento#14801 - New optional param should be last in the params list.
|
Hi @phoenix128. Thanks. |
|
Hi @phoenix128. Thank you for your contribution. |
|
Can you please give an example how we can add Add construct parameters injection for WebAPI interface |
Add construct parameters injection for WebAPI interfaces.
Description
WebAPI interfaces were relying on setter/getter methods violating the immutable stateless pattern.
This Pull Request enables the ServiceInputProcessor to get arguments directly from constructor. Setters methods are not required anymore.
Contribution checklist