How to use the global registry

Magento 1.x

Place a value to the global registry:

Mage::register('key', $value);

Get the value from the global registry by a key:

Mage::registry('key');

Magento 2

Place a value to the global registry:

/**
 * @param string $key
 * @param mixed $value 
 * @return void
 */
function df_register($key, $value) {
	/** @var \Magento\Framework\ObjectManagerInterface $om */
	$om = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Framework\Registry $registry */
	$registry = $om->get('Magento\Framework\Registry');
	$registry->register($key, $value);	
}

Get the value from the global registry by a key:

/**
 * @param string $key
 * @return mixed
 */
function df_registry($key) {
	/** @var \Magento\Framework\ObjectManagerInterface $om */
	$om = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Framework\Registry $registry */
	$registry = $om->get('Magento\Framework\Registry');
	return $registry->registry($key);
}