What is object Manager In Magento 2
-
12-03-2021 - |
Question
I am looking at the concept of the object manager, but I didn't get any proper explanation about that. I also have gone through the below link, but they are just explaining the usage, etc..
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/object-manager.html
But I want to know what is the object manager in magento2. Thanks in advance for your better support
Solution
The initializing of objects in Magento is done via what is called the object manager.
The object manager itself is an instance of the Magento\Framework\ObjectManager\ObjectManager
class that implements the Magento\Framework\ObjectManagerInterface
class. The ObjectManager class defines the following three methods:
create($type, array $arguments = [])
: This creates a new object instanceget($type)
: This retrieves a cached object instanceconfigure(array $configuration)
: This configures the di instance
The object manager can instantiate a PHP class, which can be a model, helper, or block object. Unless the class that we are working with has already received an instance of the object manager, we can receive it by passing ObjectManagerInterface
into the class constructor
, as follows:
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager
)
{
$this->_objectManager = $objectManager;
}
Get detailed information from https://www.vortexcommerce.com/magento-2-object-manager/
Hope it helps!!!