Introduction to ASP.NET 5(ASP.NET 5介绍)

    此文翻译了一大半后,才想起来已经有人翻译过一篇有点相似的博文,就参考了人家的译文。大家可以直接看原文,英文原文:https://docs.asp.net/en/latest/conceptual-overview/aspnet.html,相似中文译文:http://blogs.msdn.com/b/scottgu/archive/2015/04/30/asp-net-5.aspx

    英语不行,欢迎指正!

    By Daniel Roth

    作者Daniel Roth

    

    ASP.NET 5 is a significant redesign of ASP.NET. This topic introduces the new concepts in ASP.NET 5 and explains how they help you develop modern web apps.

    ASP.NET 5是一个经过重大重新设计的ASP.NET。这篇文章介绍ASP.NET 5的新概念并说明他们怎么帮你开发现代web应用(我以前开发的应用都是古代的)。

   What is ASP.NET 5?(什么是ASP.NET 5?)

    ASP.NET 5 is a new open-source and cross-platform framework for building modern cloud-based Web applications using .NET. We built it from the ground up to provide an optimized development framework for apps that are either deployed to the cloud or run on-premises. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. You can develop and run your ASP.NET 5 applications cross-platform on Windows, Mac and Linux. ASP.NET 5 is fully open source on GitHub.

    ASP.NET 5是使用.NET构建现代基于云的Web应用,开源的并且跨平台的框架。我们从头设计它以为部署在云端或运行在本地的应用提供优化了的开发框架。它由模块化组件以达到最小的开销,所以在你构建解决方案时能够保持灵活。你可以跨Windows,Mac和Linux开发并运行ASP.NET 5应用。ASP.NET 5在GitHub上完全开源。

    Why build(为什么构造)ASP.NET 5?

    The first preview release of ASP.NET 1.0 came out almost 15 years ago. Since then millions of developers have used it to build and run great web applications, and over the years we have added and evolved many, many capabilities to it.

    ASP.NET 1.0的第一个预览版本诞生快15年了。自此,成千上万的开发者用它建立和运行网站应用,而且多年来我们也给他增加和升级了很多功能。(自译:“从ASP.NET 1.0发布到现在已经15个年头了。从那时候数百万开发者使用它来构造并运行web应用,并且多年以来我们增加和改进了非常非常多的功能。”,感觉还差不多。)

    With ASP.NET 5 we are making a number of architectural changes that make the core web framework much leaner and more modular. ASP.NET 5 is no longer based on System.Web.dll, but is instead based on a set of granular and well factored NuGet packages allowing you to optimize your app to have just what you need. You can reduce the surface area of your application to improve security, reduce your servicing burden and also to improve performance in a true pay-for-what-you-use model.

    关于ASP.NET 5我们做了大量的结构上的改变,使核心的Web框架更精简(它不再需要System.Web.dll),并且更具有模块化(几乎所有的功能都实现了作为NuGet模块 – 允许你优化你的应用程序去获得你需要的)。

    (自译:在ASP.NET 5中,我们正在做大量的框架修改,使得核心web框架大大地简洁和更模块化。ASP.NET 5不再基于System.Web.dll,而基于一系列更细粒度、被分解到恰到好处的NuGet包,这些包能让你优化你的应用来只包括你必需的。你可以减少应用的暴露面来改进安全性,在真正的“按需付费”模式下,减少服务负担并同样提高性能。)

    ASP.NET 5 is built with the needs of modern Web applications in mind, including a unified story for building Web UI and Web APIs that integrate with today’s modern client-side frameworks and development workflows. ASP.NET 5 is also built to be cloud-ready by introducing environment-based configuration and by providing built-in dependency injection support.

    ASP.NET 5是为满足构造现代Web应用的需要而生的,包括为Web UI和Web APIs构造了统一标准的编程框架来整合今天现代样式的客户端框架和开发流程。ASP.NET 5 也被设计为云端技术,引入了基于环境的设置和内置了依赖注入支持。

    To appeal to a broader audience of developers, ASP.NET 5 supports cross-platform development on Windows, Mac and Linux. The entire ASP.NET 5 stack is open source and encourages community contributions and engagement. ASP.NET 5 comes with a new, agile project system in Visual Studio while also providing a complete command-line interface so that you can develop using the tools of your choice.

    为了吸引广大的开发者,ASP.NET 5支持在Windows,Mac和Linux上的跨平台开发。整个ASP.NET 5都已开源并鼓励社区积极参与并贡献代码。伴随ASP.NET 5,Visual Studio提供了一个新的,敏捷项目系统,当然你也可以使用完备的命令行接口来开发,你可以自由选择开发工具。

    In summary, with ASP.NET 5 you gain the following foundational improvements:

    总的来说,使用ASP.NET 5你将获得以下功能改进:

  • New light-weight and modular HTTP request pipeline(新的轻量级和更加模块化的HTTP请求管道)
  • Ability to host on IIS or self-host in your own process(能宿主在IIS或自宿主在自己的进程里)
  • Built on .NET Core, which supports true side-by-side app versioning(可以有多个版本的.NET Core并存)
  • Ships entirely as NuGet packages(像NuGet包一样装载)
  • Integrated support for creating and using NuGet packages(集成对创建和使用NuGet包的支持)
  • Single aligned web stack for Web UI and Web APIs(整合Web UI和Web APIs到统一的web模板)
  • Cloud-ready environment-based configuration(基于环境的云端技术设置)
  • Built-in support for dependency injection(内置依赖注入支持)
  • New tooling that simplifies modern web development(简化现代web开发的新工具)
  • Build and run cross-platform ASP.NET apps on Windows, Mac and Linux(构造并运行于Windows,Mac和Linux上的跨平台ASP.NET应用)
  • Open source and community focused(开源和聚集社区)

    Application anatomy(应用剖析)

    ASP.NET 5 applications are built and run using the new .NET Execution Environment (DNX). Every ASP.NET 5 project is a DNX project. ASP.NET 5 integrates with DNX through the ASP.NET Application Hosting package.

    使用新的DNX来构造ASP.NET 5应用并运行。每个ASP.NET 5项目都是DNX项目。ASP.NET 5通过ASP.NET Application Hosting包来集成DNX。

    ASP.NET 5 applications are defined using a public Startup class:

    ASP.NET 5应用定义了一个公共类“Startup”:

复制代码
public class Startup
{
     public void ConfigureServices(IServiceCollection services)
     {
     }

     public void Configure(IApplicationBuilder app)
     {
     }
}
复制代码

    The ConfigureServices method defines the services used by your application and the Configuremethod is used to define what middleware makes up your request pipeline. See Understanding ASP.NET 5 Web Apps for more details.

    “ConfigureServices”函数定义应用使用的服务,“Configure”函数定义中间件用于组成应用的请求管道。更多信息请看理解ASP.NET 5Web应用

    Services(服务)

    A service is a component that is intended for common consumption in an application. Services are made available through dependency injection. ASP.NET 5 includes a simple built-in inversion of control (IoC) container that supports constructor injection by default, but can be easily replaced with your IoC container of choice. See Dependency Injection for more details.

    服务用于满足所有应用的通用需求。通过依赖注入使服务可用。ASP.NET5包括一个简单的内置“控制反转容器”来支持默认的构造函数注入,也可以方便地用你自己选择的“控制反转容器”替换默认容器。更多内容请看依赖注入

    Services in ASP.NET 5 come in three varieties: singleton, scoped and transient. Transient services are created each time they’re requested from the container. Scoped services are created only if they don’t already exist in the current scope. For Web applications, a container scope is created for each request, so you can think of scoped services as per request. Singleton services are only ever created once.

   下面这段是根据自己的理解翻译,有可能是错的,请自行翻译:

    ASP.NET服务分为三种:单例,范围和瞬态(也可能叫过渡)。每次从容器中请求都会被重新创建的服务为瞬态服务。范围服务会限定一个范围,在此范围内请求该类服务,容器不会新建该服务的实例,而是返回以前的实例;超出此范围后,请求该类服务,容器会返回新建的该服务实例。对于Web应用,为每个请求创建一个容器范围,所以你可以认为范围限定于每次请求。单例服务则只创建一次。

    Middleware(中间件)

    In ASP.NET 5 you compose your request pipeline using Middleware. ASP.NET 5 middleware perform asynchronous logic on an HttpContext and then optionally invoke the next middleware in the sequence or terminate the request directly. You generally “Use” middleware by invoking a corresponding extension method on the IApplicationBuilder in your Configure method.

    ASP.NET 5中,你自己用中间件组建请求管道。ASP.NET 5 中间件在Http上下文中执行异步逻辑并可选地按顺序调用下个中间件或终止请求。你通常通过在“Configure”函数中相应的“IApplicationBuilder”的扩展方法使用中间件。

    ASP.NET 5 comes with a rich set of prebuilt middleware(伴随ASP.NET 5有很丰富的预制中间件):

    You can also author your own custom middleware.

    你也可以定制你自己的自定义中间件

    You can use any OWIN-based middleware with ASP.NET 5. See OWIN for details.

    在ASP.NET 5中,你可以使用任何基于OWIN(Open Web Interface for .NET,OWIN 在 .NET Web 服务器和 .NET Web 应用之间定义了一套标准的接口, 其目的是为了实现服务器与应用之间的解耦, 鼓励为 .NET Web 应用开发简单模块。此处引用了http://kb.cnblogs.com/page/509236/中的内容)的中间件。查看OWIN的更多信息。

    Servers(服务器)

    The ASP.NET Application Hosting model does not directly listen for requests, but instead relies on an HTTP server implementation to surface the request to the application as a set of feature interfaces that can be composed into an HttpContext.

    ASP.NET应用宿主模式不直接监听请求,而是依靠一个HTTP服务实现显露请求给应用,此HTTP服务作为特性接口可以被组合到HttpContext(此处翻译可能有误)。

    ASP.NET 5 includes server support for running on IIS or self-hosting in your own process. On Windows you can host your application outside of IIS using the WebListener server, which is based on HTTP.sys. You can also host your application on a non-Windows environment using the cross-platform Kestrel web server.

    ASP.NET 5 内含对运行在IIS或自宿主的服务支持。在Windows上你可以通过使用基于HTTP.sys的WebListener服务将应用宿主在IIS之外。你也可以使用跨平台的Kestrelweb服务将应用宿主在非Windows系统上。

    Web root(Web根目录)

    The Web root of your application is the root location in your project from which HTTP requests are handled (ex. handling of static file requests). The Web root of an ASP.NET 5 application is configured using the “webroot” property in your project.json file.

    Web根目录是你项目的根位置,负责处理HTTP请求(包括对静态文件的请求)。ASP.NET应用使用“project.json”文件的“webroot”属性来设置Web根目录。

    Configuration(设置)

    ASP.NET 5 uses a new configuration model for handling of simple name-value pairs that is not based on System.Configuration or web.config. This new configuration model pulls from an ordered set of configuration providers. The built-in configuration providers support a variety of file formats (XML, JSON, INI) and also environment variables to enable environment-based configuration. You can also write your own custom configuration providers. Environments, like Development and Production, are a first-class notion in ASP.NET 5 and can also be set up using environment variables:

    ASP.NET 5使用新的设置模式来管理简单的键值对,而不是基于System.Configuration和web.config。新的设置模式从一个有序的设置提供程序序列里拉取信息。内置的设置提供程序序列支持多种格式(XML,JSON,INI)以及环境变量(使基于环境的设置可用)。你也可以编写你自定义的设置提供程序。开发环境和生产环境在ASP.NET5中作为头等的概念,可以使用环境变量来设置:

复制代码
var builder = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

if (env.IsDevelopment())
{
    // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
    builder.AddUserSecrets();
}

builder.AddEnvironmentVariables();
Configuration = builder.Build();
复制代码

    See Configuration for more details on the new configuration system and Working with Multiple Environments for details on how to work with environments in ASP.NET 5.

    关于新设置系统和工作在多种环境的更多详情,请看这里

    Client-side development(客户端开发)

    ASP.NET 5 is designed to integrate seamlessly with a variety of client-side frameworks, includingAngularJSKnockoutJS and Bootstrap. See Client-Side Development for more details.

    ASP.NET 5被设计为无缝集成多种前端框架,包括AngularJSKnockoutJSBootstrap。更多详情请看客户端开发

posted @   菜鸟吊思  阅读(378)  评论(0)    收藏  举报
编辑推荐:
· 我在厂里搞 wine 的日子
· 如何通过向量化技术比较两段文本是否相似?
· 35+程序员的转型之路:经济寒冬中的希望与策略
· JavaScript中如何遍历对象?
· 领域模型应用
阅读排行:
· 独立项目运营一周年经验分享
· 独立开发,这条路可行吗?
· 文生图:介绍一个文字生成图片的开源工具
· Java简历、面试、试用期、转正
· MySQL 10 MySQL为什么有时候会选错索引?
点击右上角即可分享
微信分享提示