Question background:
I have an e-commerce site I’m developing that requires multiple controller methods to access a single session variable.
The idea:
My idea was to create a singleton style class – lets call it SessionChecker
that I would instantiate in the constructor of each controller, then call a method called CheckSessionStatus();
this in turn would check to see if the session variable was null or not, if it is null then create a new session variable.
Potential issue?
I would not be creating the SessionChecker
class as static, I would be creating a new instance in each controller. As a session can hold it’s state and be accessed over multiple pages in the app would this be ok to do? i.e accessing the session state from a new instance of the SessionChecker
class? Or would I be better off with a single static SessionChecker
class that can be just accessed from each controller constructor?
2