ASP.net的Web API:为什么每个控制器请求创建?

编程入门 行业动态 更新时间:2024-10-26 03:22:56
本文介绍了ASP的Web API:为什么每个控制器请求创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

迈克·沃森的文章依赖注入对www.asp的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:为什么每个控制器请求创建?

本文发布于:2023-11-16 21:00:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607439.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   net   ASP   API   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!