Problem accessing cart

Hello!

I’m trying to access cart from page controller by injecting CartService but when I call a method in CartService I get a null reference error in CartServiceImpl.cs on row 29
private Cart Cart => _requestModelAccessor.RequestModel.Cart;

For some reason _requestModelAccessor.RequestModel is null. I tried to inject RequestModelAccessor into another Controller, HomeController, and RequestModel is null there also.

This is the way I should access cart, right? Any ideas of what to do next?

BR Jonas

Litium version: 7.1.0

I tried this in HomeController and it was not null.
Inject the RequestModelAccessor directly and try to get the Cart.
var cart = _requestModelAccessor.RequestModel.Cart;

Try to use the CartAccessor instead of the RequestModelAccessor.

I tried it again in HomeController, it was only null in constructor, but it has value in Index method. My problem was related to using a partial view, did a change in code to skip this, then it worked. Thank you for tip about CartAccessor.
/ Jonas