Are ASP.NET controllers guaranteed only once per request?

If we want to create some objects that will be used by all the action methods in the controller, can we save them as instance variables in the controller?

Phil Haack mentions that the controllers are not intended to be reused in this old post: Asp.Net MVC Beta: Does previous RouteData override current RouteData?

But is this behavior guaranteed by one controller per request?

I do not want to be in a situation where the reused controller has data from another request.

+3
source share
3 answers

Yes (to the question in your title) and No (to the question in your message).

. , factory, , . , , , (, ), , factory.

+4

, , . , . DefaultControllerFactory, . factory, , .

+1

You can use TempData to store temporary data in the controller

0
source

Source: https://habr.com/ru/post/1721900/


All Articles