ASP.net的Web API:为什么每个控制器请求创建? [英] ASP.net Web API: Why are controllers created per request?

查看:98
本文介绍了ASP.net的Web API:为什么每个控制器请求创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迈克·沃森的文章依赖注入对www.asp.net的Web API控制器说:

Dependenecy范围和控制器终身

控制器是每个请求创建...

Controllers are created per request...

我在理解是正确的的ASP.NET Web API创建一个新的控制器实例(和满足其依赖关系)为每个传入的请求?

Am I correct in understanding that ASP.NET Web API creates a new controller instance (and satisfies its dependencies) for each incoming request?

是这种方法不浪费在其创建和破坏控制器的许多实例,当在理论上的单个实例可用于所有请求?

Is this approach not wasteful in that it creates and destroys many instances of the controller when in theory a single instance could be used for all requests?

推荐答案

一个控制器包含有关传入的请求信息(状态)。

A controller contains information (state) about the incoming request.

如果你只有一个控制器来处理很多请求,然后他们都混淆和用户可能会得到一些奇怪的结果。

If you had only one controller to handle many requests then they would all be confused and users would likely get some strange results.

这篇关于ASP.net的Web API:为什么每个控制器请求创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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