<aside> ➡️ The pages under the Engineering page are currently curated by the company's chief technical officer (CTO). To contribute, please leave a comment. How to comment?
</aside>
https://embed.notionlytics.com/wt/ZXlKd1lXZGxTV1FpT2lKalpUUXdaalZpWW1KaU5UazBPRFl6T0RsbFltRmlORFppT1dObFpETXhPQ0lzSW5kdmNtdHpjR0ZqWlZSeVlXTnJaWEpKWkNJNklrbGpiM1pzV2pOcU1VUnBRM1ZUUm1WNFRtdHlJbjA9
Large applications written in OOP are logically split into classes. To manage dependencies between classes, Magento 2 uses dependency injection during the class initialization. The dependency injection container (also known as object manager) is controlling the class object initialization process. Let's take a deeper dive into all capabilities of this entity.
An Object is an individual instance of a class. We define a class once and then produce objects out of it. Objects are also known as instances of a class.
An Object Manager is a set of high-level tools that are used by Magento to help instantiate objects. An object manager is capable of class dependency lookup and automatic resolution. You are not required to write import
or require
statements ever again.
An object manager is responsible for:
The process of automatic constructor argument resolution is called dependency injection. Dependency injection is a design pattern used to make code more flexible and easier to manage.
Instead of a class creating its own dependencies (like services or objects it needs), DI allows those dependencies to be provided from the outside.