9.10. The Request, Session, and Cookie objects MUST NOT be injected in an object constructor. They MUST be passed only as method arguments.

from the Technical guidelines

How to comply with this rule when dealing with CustomerData objects?

Since this is usually related to data specific to a customer, how can we get its values without using the session object in the constructor?

Magento core is breaking these rules for the cart section and the messages section as can be seen in:


And relying on a manager that is breaking this rule for the messages section:


  • My guess is that this guideline helps to prevent missing customer specific data on cached pages since blocks aren't executed on a page that is cached. This is not an issue for the customer data endpoint since it is not cached, so maybe such type of file falls into the "controller" category an can have session object on the constructor, but I couldn't find documentation or guideline backing this, so I'm not sure – igrossiter Jul 8 '19 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.