Get Free Audit

Module Initialization in Magento 2

Nov 28, 2017

1374 Andrey Litvin

Module Initialization in Magento 2

This is the sequel which delves into the details of Magento 2 initialization. The first article provides a comprehensive description of initialization in Magento 1. We’re sure that you will take on board the present knowledge described below.

Module definition

In Magento 2 module definition consists of two files:

  • app/code/Vendor/Module/registration.php:


The file declares module type, name, and directory.

  • app/code/Vendor/Module/etc/module.xml:


It declares module version and optional dependencies.

Module initialization process. Module declaration

The first step of module initialization is to load module declaration from registration.php. For modules installed through composer these files are listed in vendor/composer/autoload_files.php file which is generated by the composer after each installation or command upgrading.

The last file is app/etc/NonComposerComponentRegistration.php file, that allows loading modules from app/code folder.


This file lists all locations available for registration.php files and, besides, it includes them.

registration.php file consists of single call to
\Magento\Framework\Component\ComponentRegistrar::register method and passes module type, module name, and module directory as the argument.
\Magento\Framework\Component\ComponentRegistrar::register method validates module type via
\Magento\Framework\Component\ComponentRegistrar::validateType method and if the type is valid, it stores module name and path.


module.xml files are processed by \Magento\Framework\Module\ModuleList\Loader::load method.

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

Module dependencies

Module dependencies can be defined in app/code/Vendor/Module/etc/module.xml file.


Just like in Magento 1, module definitions which have already been loaded need to be sorted out according to their dependencies (dependent modules must be loaded after their dependencies) and it is performed in \Magento\Framework\Module\ModuleList\Loader::sortBySequence method.


If you’re interested in learning details related to Magento 2 module initialization, follow our blog, as a new article will be published soon.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *