Note that there are some explanatory texts on larger screens.

plurals
  1. POPuzzled about the ASP.NET MVC DefaultControllerFactory.cs Implementation
    text
    copied!<p>While investigating implementing my own <code>IControllerFactory</code> I looked into the the default implementation <code>DefaultControllerFactory</code> and was surprised to see the <code>RequestContext</code> property being set in the <code>CreateController(...)</code> method, and then being referenced in the <code>GetControllerInstance(...)</code> and <code>GetControllerType(...)</code> methods.</p> <p>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 <code>RequestContext</code> has been set to the property when you come to use it.</p> <p>Is there a guarantee in the MVC framework that only one request will be serviced by the registered <code>IControllerFactory</code> at a time?</p> <p>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.</p> <p>Thanks.</p> <p>EDIT:</p> <p>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.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload