ASP.NET MVC 3 和 4 之间的区别? [英] Difference between ASP.NET MVC 3 and 4?

查看:28
本文介绍了ASP.NET MVC 3 和 4 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个完整的列表来解释 MVC4 的所有新特性以及与 MVC3 相比发生了什么变化?

(发行说明没有多大帮助)

解决方案

MVC4 发行说明

复制粘贴:

现代 HTTP 编程模型:使用新的强类型 HTTP 对象模型直接访问和操作 Web API 中的 HTTP 请求和响应.相同的编程模型和 HTTP 管道通过新的 HttpClient 类型在客户端对称可用.

完全支持路由:ASP.NET Web API 支持 ASP.NET Routing 的全套路由功能,包括路由参数和约束.此外,使用简单的约定将操作映射到 HTTP 方法.

内容协商:客户端和服务器可以共同确定从 Web API 返回的数据的正确格式.ASP.NET Web API 提供对 XML、JSON 和表单 URL 编码格式的默认支持,您可以通过添加自己的格式化程序来扩展这种支持,甚至替换默认的内容协商策略.

模型绑定和验证:模型绑定器提供了一种从 HTTP 请求的各个部分提取数据并将这些消息部分转换为 Web API 操作可以使用的 .NET 对象的简单方法.还根据数据注释对动作参数进行验证.

过滤器:ASP.NET Web API 支持过滤器,包括众所周知的过滤器,例如 [Authorize] 属性.您可以为操作、授权和异常处理编写和插入自己的过滤器.

查询组合:在返回 IQueryable 的操作上使用 [Queryable] 过滤器属性,以支持通过 OData 查询约定查询您的 Web API.

改进的可测试性:Web API 操作不是在静态上下文对象中设置 HTTP 详细信息,而是使用 HttpRequestMessage 和 HttpResponseMessage 的实例.创建一个单元测试项目以及您的 Web API 项目,以便快速开始为您的 Web API 功能编写单元测试.

基于代码的配置:ASP.NET Web API 配置仅通过代码完成,使您的配置文件保持干净.使用提供服务定位器模式来配置扩展点.

改进了对控制反转 (IoC) 容器的支持:ASP.NET Web API 通过改进的依赖解析器抽象为 IoC 容器提供了强大的支持

自托管:除了 IIS 之外,还可以在您自己的进程中托管 Web API,同时仍然可以使用路由的全部功能和 Web API 的其他功能.

创建自定义帮助和测试页面:您现在可以使用新的 IApiExplorer 服务为您的 Web API 轻松构建自定义帮助和测试页面,以获得您的 Web API 的完整运行时描述.

监控和诊断:ASP.NET Web API 现在提供轻量级跟踪基础结构,可以轻松与现有日志记录解决方案(例如 System.Diagnostics、ETW 和第三方日志记录框架)集成.您可以通过提供 ITraceWriter 实现并将其添加到您的 Web API 配置来启用跟踪.

链接生成:使用 ASP.NET Web API UrlHelper 生成指向同一应用程序中相关资源的链接.

Web API 项目模板:从新建 MVC 4 项目向导中选择新的 Web API 项目,以快速启动并运行 ASP.NET Web API.

脚手架:使用添加控制器"对话框根据基于实体框架的模型类型快速搭建 Web API 控制器.

Is there a comprehensive list that explains all of the new features of MVC4 and what all has changed from MVC3?

(The release notes are not much helpful)

解决方案

Copied and pasted from MVC4 Release Notes:

Modern HTTP programming model: Directly access and manipulate HTTP requests and responses in your Web APIs using a new, strongly typed HTTP object model. The same programming model and HTTP pipeline is symmetrically available on the client through the new HttpClient type.

Full support for routes: ASP.NET Web API supports the full set of route capabilities of ASP.NET Routing, including route parameters and constraints. Additionally, use simple conventions to map actions to HTTP methods.

Content negotiation: The client and server can work together to determine the right format for data being returned from a web API. ASP.NET Web API provides default support for XML, JSON, and Form URL-encoded formats and you can extend this support by adding your own formatters, or even replace the default content negotiation strategy.

Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by the Web API actions. Validation is also performed on action parameters based on data annotations.

Filters: ASP.NET Web API supports filters including well-known filters such as the [Authorize] attribute. You can author and plug in your own filters for actions, authorization and exception handling.

Query composition: Use the [Queryable] filter attribute on an action that returns IQueryable to enable support for querying your web API via the OData query conventions.

Improved testability: Rather than setting HTTP details in static context objects, web API actions work with instances of HttpRequestMessage and HttpResponseMessage. Create a unit test project along with your Web API project to get started quickly writing unit tests for your Web API functionality.

Code-based configuration: ASP.NET Web API configuration is accomplished solely through code, leaving your config files clean. Use the provide service locator pattern to configure extensibility points.

Improved support for Inversion of Control (IoC) containers: ASP.NET Web API provides great support for IoC containers through an improved dependency resolver abstraction

Self-host: Web APIs can be hosted in your own process in addition to IIS while still using the full power of routes and other features of Web API.

Create custom help and test pages: You now can easily build custom help and test pages for your web APIs by using the new IApiExplorer service to get a complete runtime description of your web APIs.

Monitoring and diagnostics: ASP.NET Web API now provides light weight tracing infrastructure that makes it easy to integrate with existing logging solutions such as System.Diagnostics, ETW and third party logging frameworks. You can enable tracing by providing an ITraceWriter implementation and adding it to your web API configuration.

Link generation: Use the ASP.NET Web API UrlHelper to generate links to related resources in the same application.

Web API project template: Select the new Web API project form the New MVC 4 Project wizard to quickly get up and running with ASP.NET Web API.

Scaffolding: Use the Add Controller dialog to quickly scaffold a web API controller based on an Entity Framework based model type.

这篇关于ASP.NET MVC 3 和 4 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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