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?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

Raising a bilingual kid. When should we introduce the majority language?

How to break 信じようとしていただけかも知れない into separate parts?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Meaning of "Not holding on that level of emuna/bitachon"

Assertions In A Mock Callout Test

Can a Wizard take the Magic Initiate feat and select spells from the Wizard list?

What's the connection between Mr. Nancy and fried chicken?

How was Lagrange appointed professor of mathematics so early?

What came first? Venom as the movie or as the song?

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

When does Bran Stark remember Jamie pushing him?

2 sample t test for sample sizes - 30,000 and 150,000

Do chord progressions usually move by fifths?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

How to leave only the following strings?

Why doesn't the university give past final exams' answers?

Salesforce - multiple pre production environments

Why do C and C++ allow the expression (int) + 4*5?

Has a Nobel Peace laureate ever been accused of war crimes?

Lights are flickering on and off after accidentally bumping into light switch

Will I be more secure with my own router behind my ISP's router?

Converting a text document with special format to Pandas DataFrame



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,0561321




                4,0561321



























                    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

                    Sum ergo cogito? 1 nng

                    419 nièngy_Soadمي 19bal1.5o_g

                    Queiggey Chernihivv 9NnOo i Zw X QqKk LpB