While investigating implementing my own IControllerFactory
I looked into the the default implementation DefaultControllerFactory
and was surprised to see the RequestContext
property being set in the CreateController(...)
method, and then being referenced in the GetControllerInstance(...)
and GetControllerType(...)
methods.
The reason for my surprise is that as the factory is instantiated at Application start-up that same instance is used for all requests, so if multiple requests are received at the same time you have no guarantee which requests RequestContext
has been set to the property when you come to use it.
Is there a guarantee in the MVC framework that only one request will be serviced by the registered IControllerFactory
at a time?
If I am missing something here please enlighten me, as the implementaiton of my controller will be simpler if I have state between method calls during a requests lifecycle.
Thanks.
EDIT:
The answers given are as I expected but miss the main point of the question. The fact is the DefautlControllerFactory supplied as a part of the MVC framework is storing the RequestContext as if it has state - look at the source.
I believe this to be wrong and am looking for clarification (which I think I have seeing as both answers agree with my thoughts). I have cross posted to thte ASP.NET MVC Forums.