开发者

Controller - ASP.NET MVC - Does more than one instance of a controller get created per App-Domain? If so under what conditions?

开发者 https://www.devze.com 2023-03-16 15:58 出处:网络
Does more than one instance of a controller get creat开发者_Python百科ed per App-Domain? If so under what conditions?A new instance of a controller is created for each request by MVC, so you may end u

Does more than one instance of a controller get creat开发者_Python百科ed per App-Domain? If so under what conditions?


A new instance of a controller is created for each request by MVC, so you may end up with multiple instances running on different threads.

There is nothing stopping you from creating multiple instances yourself.

The controller should be stateless.


As Jakub has said, using the default controller factory, you get one controller instance per request.

Always ensure that the controllers are stateless - in the event that your application is ever run on a web farm or, say, Windows Azure, you can't even guarantee that subsequent requests are served by the same machine.

Instead, put any data that must be preserved across requests into Session State (or use your back-end data store).

0

精彩评论

暂无评论...
验证码 换一张
取 消