A software dependency identifies one software component’s reliance on another for proper functioning. A core principle of Magento architecture is the minimization of software dependencies. Instead of being closely interrelated with other modules, modules are optimally designed to be loosely coupled. Loosely coupled modules require little or no knowledge of other modules to perform their tasks.
Each Magento module is responsible for a unique feature. In practice, this means that:
Several modules cannot be responsible for one feature.
One module cannot be responsible for several features.
Module dependencies on other modules must be declared explicitly. You must also declare any dependency upon other components (for example, a theme, language package, or library).
Removing or disabling a module does not result in disabling other modules.
What components can modules depend upon?
Although Magento architecture favors loosely coupled software components, modules can contain dependencies upon these software components:
Note: You can lose the historical information contained in a module if the module is removed or disabled. We recommend alternative storage of module information before you remove or disable a module.
Managing module dependencies
At a high level, there are three main steps for managing module dependencies:
Name and declare the module in the
Declare any dependencies that the module has (whether on other modules or on a different component) in the module’s
(Optional) Define the desired load order of config files and
.cssfiles in the
Example: Module A declares a dependency upon Module B. Thus, in Module A’s
module.xml file, Module B is listed in the
<sequence> list, so that B’s files are loaded before A’s. Additionally, you must declare a dependency upon Module B in A’s
composer.json file. Furthermore, in the deployment configuration, Modules A and B must both be defined as enabled.
1 2 3 4 5 6 7 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Module_A" setup_version="1.0.0"> <sequence> <module name="Module_B" /> </sequence> </module> </config>
After installing the module and opening
app/etc/config.php, you are able to see that the Module_B was loaded before Module_A:
1 2 3 4 5 6 7 8 return [ 'modules' => [ ... 'Module_B' => 1, 'Module_A' => 1, ... ] ];