I'm initializing an object \Magento\Framework\Registry via a function create() of Magento\Framework\ObjectManagerInterface in Controller. After, I try to register a value to Registry Class.
$registry = $this->_objectManager->create('Magento\Framework\Registry');
$registry->register('test', '123456');
I try to get this value in Block. However, it return null.
$registry->registry('test'); //return null
If I inject \Magento\Framework\Registry to the constructor, it working normally.
public function __construct(
Magento\Framework\App\Action\Context $context,
\Magento\Framework\Registry $registry
) {
parent::__construct($context);
$this->registry = $registry;
}
My question: Why this two ways different initialization?
Any help is appreciated.