<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.

What is an object?

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.

What is an object manager?

The Object Manager is a Dependency Injection Container used by Magento 2. It’s responsible for resolving class dependencies and instantiating objects as needed. It eliminates the need for manual instantiation using new and allows Magento to manage lifecycle, scope, and preferences for class instances.

❌ Example of discouraged direct use:

$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();
$productRepo = $objectManager->get(\\Magento\\Catalog\\Api\\ProductRepositoryInterface::class);

Direct usage like above is discouraged. Use Dependency Injection instead.

What is an object manager capable of?

An object manager is responsible for: