What is Context Object purpose in any class's constructor DI ? How Context works? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Context dependency in Magento2Is this really the best DI works when extending class constructors?How to debug Call to a member function dispatch() on null ininternalMagentoFrameworkAppActionAction.php on line 91Magento 2 Incorrect dependency in class already exists in context objectMagento 2 : Problem extending a BlockHow to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleModel Override issue in magento 2After rewrite MagentoCustomerModelAccountManagement giving me fatal errorDI not working in ControllerMonolog Error After 2.2 UpgradeI am trying to override multishipping.php file in vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpPHP fatal error: Uncaught TypeError: Argument 2 passed to MagentoCatalogPluginBlockTopmenuMagento 2.3 Can't view module's front end page output?

What is a more techy Technical Writer job title that isn't cutesy or confusing?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

Weaponising the Grasp-at-a-Distance spell

How to write capital alpha?

The test team as an enemy of development? And how can this be avoided?

Sally's older brother

Random body shuffle every night—can we still function?

Simple Line in LaTeX Help!

After Sam didn't return home in the end, were he and Al still friends?

What order were files/directories output in dir?

What does it mean that physics no longer uses mechanical models to describe phenomena?

What does the writing on Poe's helmet say?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Trying to understand entropy as a novice in thermodynamics

I can't produce songs

Why is a lens darker than other ones when applying the same settings?

Did any compiler fully use 80-bit floating point?

Why shouldn't this prove the Prime Number Theorem?

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

Asymptotics question

How to align enumerate environment inside description environment

How to ask rejected full-time candidates to apply to teach individual courses?

Tannaka duality for semisimple groups

Nose gear failure in single prop aircraft: belly landing or nose-gear up landing?



What is Context Object purpose in any class's constructor DI ? How Context works?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Context dependency in Magento2Is this really the best DI works when extending class constructors?How to debug Call to a member function dispatch() on null ininternalMagentoFrameworkAppActionAction.php on line 91Magento 2 Incorrect dependency in class already exists in context objectMagento 2 : Problem extending a BlockHow to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleModel Override issue in magento 2After rewrite MagentoCustomerModelAccountManagement giving me fatal errorDI not working in ControllerMonolog Error After 2.2 UpgradeI am trying to override multishipping.php file in vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpPHP fatal error: Uncaught TypeError: Argument 2 passed to MagentoCatalogPluginBlockTopmenuMagento 2.3 Can't view module's front end page output?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








22















In most of the class's Constructors, a Context object is passed . I couldn't understand how this Context Obj works . I also noticed that sometimes this is passed to parent class's constructor like below.



public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoCatalogModelDesign $catalogDesign,
MagentoCatalogModelSession $catalogSession,
....
parent::__construct(
$context,
$layoutFactory,


Can you please explain how this specific context object works ?










share|improve this question






























    22















    In most of the class's Constructors, a Context object is passed . I couldn't understand how this Context Obj works . I also noticed that sometimes this is passed to parent class's constructor like below.



    public function __construct(
    MagentoFrameworkAppActionContext $context,
    MagentoCatalogModelDesign $catalogDesign,
    MagentoCatalogModelSession $catalogSession,
    ....
    parent::__construct(
    $context,
    $layoutFactory,


    Can you please explain how this specific context object works ?










    share|improve this question


























      22












      22








      22


      9






      In most of the class's Constructors, a Context object is passed . I couldn't understand how this Context Obj works . I also noticed that sometimes this is passed to parent class's constructor like below.



      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoCatalogModelDesign $catalogDesign,
      MagentoCatalogModelSession $catalogSession,
      ....
      parent::__construct(
      $context,
      $layoutFactory,


      Can you please explain how this specific context object works ?










      share|improve this question
















      In most of the class's Constructors, a Context object is passed . I couldn't understand how this Context Obj works . I also noticed that sometimes this is passed to parent class's constructor like below.



      public function __construct(
      MagentoFrameworkAppActionContext $context,
      MagentoCatalogModelDesign $catalogDesign,
      MagentoCatalogModelSession $catalogSession,
      ....
      parent::__construct(
      $context,
      $layoutFactory,


      Can you please explain how this specific context object works ?







      magento2 architecture






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 '16 at 7:01









      Fabian Schmengler

      55.4k21139354




      55.4k21139354










      asked Mar 28 '16 at 4:35









      learnerlearner

      11614




      11614




















          2 Answers
          2






          active

          oldest

          votes


















          28














          Note that there are different Context objects, in this case it's MagentoFrameworkAppActionContext and to understand it, you should read it as "ActionContext". It represents the application context in which the action is executed. In other words, it gives you access to all objects with application state that a controller action needs, for example the registry or the request object.



          The context classes don't have own functionality, they are just a container for other objects. You can see them as shortcut to not have 20 parameters in each controller action. All common parameters are merged in the context object.






          share|improve this answer























          • how could i know which object are contained by different $context?

            – LucScu
            Jun 9 '16 at 6:48











          • @LucaS look at their source code. You find the contained classes in the context constructor

            – Fabian Schmengler
            Jun 9 '16 at 7:22


















          12














          Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.



          In Magento 1 Abstract classes with a lot of "helper" behaviour were considered a convenient API for class extender. This caused huge numbers of methods and implicit dependencies in abstract classes (AbstractModel, AbstractBlock, AbstractAction)



          In Magento 2 inheritance-based APIs (more precisely SPIs) are discouraged, but many legacy APIs still exist. Initially we planned to gradually remove extra behaviour from abstract classes. And to not break all extenders when we would remove some dependency from constructor, we introduced Context objects.



          Current plan is to abandon inheritance-based APIs with interface-based APIs at some point.






          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108163%2fwhat-is-context-object-purpose-in-any-classs-constructor-di-how-context-works%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            28














            Note that there are different Context objects, in this case it's MagentoFrameworkAppActionContext and to understand it, you should read it as "ActionContext". It represents the application context in which the action is executed. In other words, it gives you access to all objects with application state that a controller action needs, for example the registry or the request object.



            The context classes don't have own functionality, they are just a container for other objects. You can see them as shortcut to not have 20 parameters in each controller action. All common parameters are merged in the context object.






            share|improve this answer























            • how could i know which object are contained by different $context?

              – LucScu
              Jun 9 '16 at 6:48











            • @LucaS look at their source code. You find the contained classes in the context constructor

              – Fabian Schmengler
              Jun 9 '16 at 7:22















            28














            Note that there are different Context objects, in this case it's MagentoFrameworkAppActionContext and to understand it, you should read it as "ActionContext". It represents the application context in which the action is executed. In other words, it gives you access to all objects with application state that a controller action needs, for example the registry or the request object.



            The context classes don't have own functionality, they are just a container for other objects. You can see them as shortcut to not have 20 parameters in each controller action. All common parameters are merged in the context object.






            share|improve this answer























            • how could i know which object are contained by different $context?

              – LucScu
              Jun 9 '16 at 6:48











            • @LucaS look at their source code. You find the contained classes in the context constructor

              – Fabian Schmengler
              Jun 9 '16 at 7:22













            28












            28








            28







            Note that there are different Context objects, in this case it's MagentoFrameworkAppActionContext and to understand it, you should read it as "ActionContext". It represents the application context in which the action is executed. In other words, it gives you access to all objects with application state that a controller action needs, for example the registry or the request object.



            The context classes don't have own functionality, they are just a container for other objects. You can see them as shortcut to not have 20 parameters in each controller action. All common parameters are merged in the context object.






            share|improve this answer













            Note that there are different Context objects, in this case it's MagentoFrameworkAppActionContext and to understand it, you should read it as "ActionContext". It represents the application context in which the action is executed. In other words, it gives you access to all objects with application state that a controller action needs, for example the registry or the request object.



            The context classes don't have own functionality, they are just a container for other objects. You can see them as shortcut to not have 20 parameters in each controller action. All common parameters are merged in the context object.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 '16 at 6:59









            Fabian SchmenglerFabian Schmengler

            55.4k21139354




            55.4k21139354












            • how could i know which object are contained by different $context?

              – LucScu
              Jun 9 '16 at 6:48











            • @LucaS look at their source code. You find the contained classes in the context constructor

              – Fabian Schmengler
              Jun 9 '16 at 7:22

















            • how could i know which object are contained by different $context?

              – LucScu
              Jun 9 '16 at 6:48











            • @LucaS look at their source code. You find the contained classes in the context constructor

              – Fabian Schmengler
              Jun 9 '16 at 7:22
















            how could i know which object are contained by different $context?

            – LucScu
            Jun 9 '16 at 6:48





            how could i know which object are contained by different $context?

            – LucScu
            Jun 9 '16 at 6:48













            @LucaS look at their source code. You find the contained classes in the context constructor

            – Fabian Schmengler
            Jun 9 '16 at 7:22





            @LucaS look at their source code. You find the contained classes in the context constructor

            – Fabian Schmengler
            Jun 9 '16 at 7:22













            12














            Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.



            In Magento 1 Abstract classes with a lot of "helper" behaviour were considered a convenient API for class extender. This caused huge numbers of methods and implicit dependencies in abstract classes (AbstractModel, AbstractBlock, AbstractAction)



            In Magento 2 inheritance-based APIs (more precisely SPIs) are discouraged, but many legacy APIs still exist. Initially we planned to gradually remove extra behaviour from abstract classes. And to not break all extenders when we would remove some dependency from constructor, we introduced Context objects.



            Current plan is to abandon inheritance-based APIs with interface-based APIs at some point.






            share|improve this answer



























              12














              Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.



              In Magento 1 Abstract classes with a lot of "helper" behaviour were considered a convenient API for class extender. This caused huge numbers of methods and implicit dependencies in abstract classes (AbstractModel, AbstractBlock, AbstractAction)



              In Magento 2 inheritance-based APIs (more precisely SPIs) are discouraged, but many legacy APIs still exist. Initially we planned to gradually remove extra behaviour from abstract classes. And to not break all extenders when we would remove some dependency from constructor, we introduced Context objects.



              Current plan is to abandon inheritance-based APIs with interface-based APIs at some point.






              share|improve this answer

























                12












                12








                12







                Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.



                In Magento 1 Abstract classes with a lot of "helper" behaviour were considered a convenient API for class extender. This caused huge numbers of methods and implicit dependencies in abstract classes (AbstractModel, AbstractBlock, AbstractAction)



                In Magento 2 inheritance-based APIs (more precisely SPIs) are discouraged, but many legacy APIs still exist. Initially we planned to gradually remove extra behaviour from abstract classes. And to not break all extenders when we would remove some dependency from constructor, we introduced Context objects.



                Current plan is to abandon inheritance-based APIs with interface-based APIs at some point.






                share|improve this answer













                Context objects were introduced to isolate third party developers from changes in constructors of abstract classes.



                In Magento 1 Abstract classes with a lot of "helper" behaviour were considered a convenient API for class extender. This caused huge numbers of methods and implicit dependencies in abstract classes (AbstractModel, AbstractBlock, AbstractAction)



                In Magento 2 inheritance-based APIs (more precisely SPIs) are discouraged, but many legacy APIs still exist. Initially we planned to gradually remove extra behaviour from abstract classes. And to not break all extenders when we would remove some dependency from constructor, we introduced Context objects.



                Current plan is to abandon inheritance-based APIs with interface-based APIs at some point.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 6 '16 at 10:01









                Anton KrilAnton Kril

                4,0461321




                4,0461321



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108163%2fwhat-is-context-object-purpose-in-any-classs-constructor-di-how-context-works%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form