For Catalog, Checkout, Customer and other Magento session like
\Magento\Catalog\Model\Session
\Magento\Checkout\Model\Session
\Magento\Customer\Model\Session
Because Magento 2 is no longer using core session like in magento 1.
protected $customerSession;
public function __construct(
....
\Magento\Customer\Model\Session $customerSession,
....
){
....
$this->customerSession = $customerSession;
....
}
To set and get the value of session.
$this->customerSession->setCustomerName('Bob'); //Set Value
$this->customerSession->getCustomerName(); // Get Value
$this->customerSession->unsCustomerName(); // Unset Value
You can use above Factory method by creating function or directly by using objectManager
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
$customerSession->setCustomerName('Bob');
$customerSession->getCustomerName();