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;
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
add a comment |
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
add a comment |
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
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
magento2 architecture
edited Mar 28 '16 at 7:01
Fabian Schmengler
55.4k21139354
55.4k21139354
asked Mar 28 '16 at 4:35
learnerlearner
11614
11614
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 6 '16 at 10:01
Anton KrilAnton Kril
4,0461321
4,0461321
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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