How to Use Registry in Magento 2

How to Use Registry in Magento 2

Magento registry stores data to memory which is specific to a particular request and for a duration of that request only. The Mage class is instantiated as a singleton object for every request and the instantiated Mage object remains in memory and is accessible in all classes until the request completes and the response is sent.

Magento 2 allows registering global variable that supports the static registry method. But, instead of using  Mage :: register() and Mage::registry() in Magento 1, apply /Magento/Framework/Registry. It accepts the settings and the registry of the restored data. In this tutorial, we will learn to create and use your own custom registry in Magento 2.

Follow the below code to use Registry in Magento 2:

I hope you readers got a proper guide on how to use registry in Magento 2. Any doubts about using registry in Magento 2 will be entertained in the comments section!
Please give us your reviews about the article which will help us perform better in further articles 🙂

Award 5 stars for our work if you found it useful!
Happy Coding!

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

(based on 38 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

2 comments On How to Use Registry in Magento 2

Leave a reply:

Your email address will not be published.