Introduction to ASP.NET 5

Original author: ScottGu
  • Transfer

The first preliminary release of ASP.NET 1.0 was released almost 15 years ago and since then millions of developers have used it to create and run various applications. And over the years we have added a huge amount of code and features.

I am very excited today because I am writing news about the new ASP.NET release that our team is working on and called ASP.NET 5. This release is one of the most significant architecture updates we have ever made. As part of this release, we have made ASP.NET more compact, modular and cross-platform, as well as oriented to cloud hosting. ASP.NET 5 Preview is available for download at the latest Visual Studio 2015 CTP, which was recently available.

ASP.NET 5 is an open source web framework designed to create modern web applications and work on Windows, Linux and Mac. It includes the MVC 6 framework and the Web API. ASP.NET 5 will also become the basis for SignalR 3. Initially, ASP.NET 5 is designed to run on the .NET CoreCLR, but can also be run on the full .NET Framework.

In ASP.NET 5, we made a number of architectural changes that made the core of the web framework much more compact (it no longer needs System.Web.dll) and modular (now most of the functions are made in the form of NuGet packages, allowing you to have only that what you need). With ASP.NET 5 you get the following changes:
  • Assembly and operation of cross-platform ASP.NET applications on Windows, Linux and Mac.
  • Work on .NET Core
  • New toolkit that simplifies the development of modern web applications
  • Single technology stack for Web UI and Web APIs
  • Cloud-ready environment-based configuration
  • Native support for creating and using NuGet packages
  • Native Dependency Injection Support
  • The ability to host in IIS or in your own application

And as the end result - ASP.NET, which you are familiar with, but which has become much more well-tuned to the modern realities of web development.

Flexible cross-platform runtime

ASP.NET 5 runs on two runtimes to provide you with a choice: where to host your application. The choices for runtimes are as follows:

.NET Core is a completely new, cross-platform runtime that weighs almost nothing. When you choose .NET Core, you can take advantage of completely new benefits:
1) You have the right to supply .NET Core runtime directly with your application, and this means that your application will work on it, and not on the version that is installed on the system. Your rutime version will work side by side with other versions that pull up other applications. You can upgrade your version of runtime to a newer one without fear that this will affect the operation of other applications. This makes the deployment of new versions of applications and the framework much easier and makes it possible to update while other applications are running.
2) Your application depends only on those features that it really needs. Thus, you will never be asked to update services that are not relevant to your application. This makes application deployment much faster and easier without affecting other applications.
3) Your application can now be cross-platform. We will provide you with a cross-platform version of .NET Core for Windows, Linux, and Mac OS X. Regardless of which operating system you choose for development and which operating system you choose for deployment, you can use .NET everywhere. The cross-platform version of runtime has not yet been released, but we are actively working on it and promise to roll out the official Preview very soon.

.NET Framework- The .NET Core API is currently much more limited when compared with the full version of the .NET Framework, so you will probably have to make a number of changes to make your application run on .NET Core. If you do not want to update your application, then you can run it on ASP.NET 5 on the full .NET Framework (version 4.5.2 or higher). By doing so, you get a complete set of .NET Framework APIs, and your applications will work without any changes.

MVC 6 is a unified programming model.

MVC, Web API, and Web Pages provide additional functionality and are often used together in solution development (SLN). However, in earlier releases of ASP.NET, these frameworks were developed separately, and therefore contained a huge amount of duplication and inconsistency. With MVC 6, we combined all of these models into a single programming model. Now you have the opportunity to create web applications that contain both Web UI and services without the need to "reconcile" the differences between these frameworks. You can also seamlessly transfer your simple Web pages application to a modern and reliable MVC.
Now you can return Razor views data from the same controller and using the same MVC filter pipeline.
In addition to unifying existing frameworks, we are adding new features that make server development easier. For example, Tag helpers. They allow you to use HTML helpers in your views simply by expanding the semantics of tags in the markup:
i.e. instead of writing like this:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label"})
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.UserName, "", new { @class ="text-danger" })

You will write like this:

Tag helpers make your presentation more “natural” and readable. They also simplify customizing HTML helpers output.

For other examples of MVC6 applications, please follow the link: tutorials

Modern Web Development

This week we released ASP.NET 5 preview, which, among other things, includes some features that will allow you to make applications a little better:

Dynamic Development
In Visual Studio 2015, we will use dynamic compilation. You no longer have to recompile applications each time to see the changes. Instead, simply (1) change the code, (2) save the changes, (3) update the browser and (4) you will see how your changes automatically update the application.

You will gain new development experience, which now looks more like working with interpreted languages ​​than working with compiled languages.

You can also use other code editors (for example, Sublime Text 3 with an add-in for working with C # projects) to work with ASP.NET 5 projects. Any Visual Studio feature can be found in command-line tools, which in the meantime are cross-platform (this means that edit-in-place is also available on both Mac OS X and Linux).

Integration with popular Web development tools
Another feature of the future MS Visual Studio 2015 is the built-in support for Bower, Grunt and Gulp - popular open source projects, which, in our opinion, should be indispensable tools for each developer.
  • Bower is a client-side package manager that includes both JavaScipt and CSS
  • Grunt and Gulp are task runners that help automate the workflow of your applications. You can use Grunt or Gulp for tasks such as building LESS, CoffeeScript, TypeScript files. Launch JSLint, minify JS files.

Bower: to add a JavaScript library to your ASP.NET project, add it directly in the bower.json configuration file:

Do not forget that Visual Studio provides you with IntelliSense with a list of available packages. The next time you open the solution, Visual Studio will automatically restore all the missing packages, so there is no need for you to put them all in the version control system.

For server-side packages, you should of course use NuGet.

Grunt:in modern Web development, you can notice for yourself that you are engaged in a huge number of different and different tasks from development just to build your application: you collect LESS, TypeScript, CoffeeScript files, minify JavaScript, run unit JS tests, and so on, and so on similar ... Each team has its own set of requirements, which are based on the tools used in the project. Task runners make coordinating and managing these tasks easier. Visual Studio supports two of the most popular runners: Grunt and Gulp.

Here is an example: for example, you need Grunt to collect LESS files. Then you should open package.json and add the grunt-contrib-less package, which is a third-party plugin to Grunt.

Use the new Task Runner Explorer manager in Visual Studo 2015 to assign a task to a specific build step (pre-build, post-build, clean, or when the SLN file is open).

This makes the automation of common tasks a truly non-stop operation.

Simplified Dependency Management
In ASP.NET 5, you manage dependencies by adding / removing and updating NuGet packages. You can use the NuGet package manager or simply edit the JSON file (project.json), which contains a list of NuGet packages and a list of versions that are used in your project. The project.json file is easy to work with, and you can naturally edit it in any file editor, which allows you to update dependencies when your application is running in the cloud.
Project.json looks something like this:

In Visual Studio 2015, IntelliSense helps you find available NuGet packages that you can add as dependencies:

IntelliSence will also help you with a list of available versions:

Open source

We are developing ASP.NET 5 in the open GitHub repository. You can see the code and see all the changes that have been made by us or the community. You can download this code, make changes to it and make a Pull Request. We believe that by opening the source code, we give you the opportunity to understand what is happening inside the product or having figured out everything, start making changes to ASP.NET yourself.

Want to know more about .NET internals?

Then come to our light! Soon, a series of CLRium # 2 seminars will be held in Moscow (April 03–04), Yekaterinburg (May 17) and St. Petersburg (May 29–30) (online translation is included). We will discuss the future of .NET: we will talk about the anatomy of the new CoreCLR, ASP.NET 5, RyuJIT features, hardcore Roslyn examples and the offspring of CoreFx! An endless stream of interesting and useful knowledge will help you not only understand much better how your own C # programs work, but also prepare you for a bright .NET future in which you can use the platform's full power!


Also popular now: