-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Enable WebAPI interface to handle parameters through constructor #14801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -82,6 +89,7 @@ public function __construct( | |||
AttributeValueFactory $attributeValueFactory, | |||
CustomAttributeTypeLocatorInterface $customAttributeTypeLocator, | |||
MethodsMap $methodsMap, | |||
\Magento\Framework\ObjectManager\ConfigInterface $config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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