有没有为每个请求一个新的控制器实例? [英] Is there a new controller instance for each request?

查看:128
本文介绍了有没有为每个请求一个新的控制器实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,有没有为每个请求一个新的控制器实例?这是如何实际工作?我看过类似的东西传入请求路由选择后正确的控制器..和我想它会创建一个新实例,然后控制器进一步处理请求。如果是这样的话,大约重定向到其他动作的动作是什么?这是否启动新的路由处理和控制器的新实例,也?

I am just wondering, is there a new controller instance for each request? How does this actually work? I read something like that after an incoming request routing selects correct controller.. and I guess it creates a new instance of that and then the controller handles the request further. If that is so, what about actions redirecting to other actions? Does that initiate new routing process and new instance of controller, too?

先谢谢了。

推荐答案

是的,一个新的实例实例中的每个请求,并在请求结束时被销毁。

Yes, a new instance in instantiated for each request, and destroyed at the end of the request.

每个路由是由MvcRouteHandler的实例处理。默认的处理程序调用到的ControllerFactory,它的基础上,URL标记,通过反射调用Activator.CreateInstance()实例化一个新的控制器。

Each route is handled by an instance of an MvcRouteHandler. The default handler calls into the ControllerFactory, which, based on the url tokens, instantiates a new controller via a reflection call to Activator.CreateInstance().

这篇关于有没有为每个请求一个新的控制器实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆