1

I was googling on Sessions and mvc3, and I found this link. To that question a marc-gravell answered

The session only really exists during the processing of an action - I wouldn't expect it to be valid in the constructor of a controller. For example, the controller might (for all I know) be re-used between requests.

I think that may not be the case by reading further on mvc requests and creation of controller, I found this:

A Controller is created for every request by the ControllerFactory (which by default is the DefaultControllerFactory).

So I think, Marc was incorrect and we can simply check the Session exist or not from controller's constructor.

In short, should I follow Marc's answer, or not? Or is there any better way to check sessions with mvc?

Community
  • 1
  • 1
Sharun
  • 3,022
  • 6
  • 30
  • 59
  • Not everyone uses the default factories... Making an assumption that such things are per-request could be very dangerous. – Marc Gravell Jun 28 '13 at 15:47
  • @MarcGravell But I think that is the default behavior of MVC – Sharun Jul 02 '13 at 03:51
  • yes, but you should *design* for what is the *allowed* behavior of MVC – Marc Gravell Jul 02 '13 at 06:46
  • @MarcGravell: So you are saying that, controller should not be created with each request? How can I achieve that? – Sharun Jul 02 '13 at 06:55
  • 1
    I didn't say "should not"; I am trying to make the point that it *might not*, and that your code shouldn't make assumptions about that. The "How can I achieve that?" is simply: *provide your own factory* – Marc Gravell Jul 02 '13 at 08:29

0 Answers0