ASP.NET 5 By Numbers

There's a lot of confusion surrounding the numbers relating to the impending release of the next version of ASP.NET. This post takes a look at the main ones and seeks to explain their significance.

5

The new version of ASP.NET is called ASP.NET 5. It is a framework for developing web applications using the Model View Controller architecture. It also provides a RESTful services framework. In addition, a framework for building "real-time" web functionality will be included in the form of the next version of SignalR. ASP.NET 5 will not include any type of Web Forms development framework.

5 is also the number given to a new version of the .NET framework, also known as "Core50". I'll refer to it as .NET Core from now on. The .NET Core framework is a refactored version of .NET. It has been designed to include only a minimum subset of the full framework's features, massively reducing its footprint. Other features will be available as plugins via Nuget. This is particularly useful when you want to squeeze as much from a your cloud platform as you can. There will also be a cross-platform version of .NET Core. This will enable you to deploy ASP.NET apps that have been designed to target .NET Core on Mac and UNIX/Linux operating systems. The .NET Core framework can be bin-deployed with the app, making it possible to runs ASP.NET apps on the same server that target multiple versions of .NET Core. In other words, you won't have to wait for your hosting company to patch a server to be able to take advantage of any newer versions of the framework. The .NET Core framework will not include Web Forms, Windows Forms, WPF, WCF, Silverlight, System.Drawing, Datatables etc.

Some of the omissions, such as System.Drawing, may mean that you cannot migrate your existing application to .NET Core straightaway - if you use System.Drawing for generating thumbnails, for example. This kind of functionality will be made available as Nuget packages - in time. A tool should be made available to enable you to check the compatibility of your current app with.NET Core.

4.5.2

This is the current version of the full .NET framework. You can choose to target your ASP.NET 5 application against this version. You can actually target your ASP.NET 5 application against 4.5.1. ASP.NET 5 applications that target the full version of .NET will be able to take advantage of the entire .NET framework, but will not be cross platform.

4.6

The next full version of the .NET framework is 4.6. As well as .NET Core, you can target ASP.NET 5 applications to run on .NET 4.6. ASP.NET applications that have been designed to work with .NET 4.6 may not be compatible with .NET Core. The next version of ASP.NET Web Forms is also 4.6. It will include some enhancements such as async model binding, HTTP 2 and the ability to use the new Roselyn compiler. Existing ASP.NET applications (Web Forms, MVC 5 or lower, Web Pages) should all run on .NET 4.6 without modification.

6

ASP.NET 5 will see MVC, Web API and Web Pages merged into one framework called MVC 6. This merging will result in the removal of odd duplications among the existing frameworks which aren't quite duplications, such as different controllers for MVC and Web API, or similar looking HTML helpers in both MVC and Web Pages which are implemented completely differently. Web Pages won't be available as a development model when ASP.NET 5 is released to market, so it's difficult to say at this stage what it will look like, but one can assume that traditional MVC features like Model Binding will be available to it. We are told that Web Pages will be available in the first update after RTM. Microsoft still see Web Pages as an important platform for beginners and SPA development.

MVC 6 will see the introduction of some new features, the most noticeable of which are Tag Helpers and View Components. Tag helpers are an optional replacement for Html helpers in your views. Here's a standard piece of MVC 5 (from the default template's Register.cshtml view:

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()
    <h4>Create a new account.</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
        </div>
    </div>

And here's how it will look when the HTML helpers are replaced with Tag helpers:

<form asp-controller="Account" asp-action="Register" method="post" class="form-horizontal" role="form">
    <h4>Create a new account.</h4>
    <hr />
    <div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
    <div class="form-group">
        <label asp-for="UserName" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="UserName" class="form-control" />
            <span asp-validation-for="UserName" class="text-danger"></span>
        </div>
    </div>

This feature is still under development and there is no support for it in Visual Studio 2015 CTP 6 (Beta 3) - unless my installation went wrong.

View Components are intended to replace the widgets that you usually call into your layout or view using Html.Action, such as menus, tag clouds, the Archive listing on the right hand side of this page and so on. Here's a very simple view component that generates a greeting based on the time of day:

namespace WebApplication1.ViewComponents
{
    using Microsoft.AspNet.Mvc;
    using System;

    public class GreetingViewComponent : ViewComponent
    {
        public IViewComponentResult Invoke()
        {
            var greeting = "Good Morning!";
            if (DateTime.Now.Hour > 12)
            {
                greeting = "Good Afternoon!";
            }
            if (DateTime.Now.Hour > 17)
            {
                greeting = "Good Evening!";
            }
            return View("Index", greeting);
        }
    }
}

The view component needs a view:

@model string
<h3>@Model</h3>

It is rendered as a result of a call to Component.Invoke in the parent view:

<div>
    @Component.Invoke("Greeting")
</div>

There is also a Component.InvokeAsync method so you can make your view component asynchronous. You can read more about view components on the ASP.NET site.

7

Although not part of ASP.NET, the next version of the Entity Framework is also under development. Entity Framework 7 will be released with the RTM of ASP.NET 5, although the EF team warn that EF 7 will not be the "go-to-release" at that point. What should be ready at that stage is a basic ORM package that will run on .NET Core. It will not include lazy loading, inheritance mapping and will only target SQL Server. If you don't have any reason to target the cloud optimised cross-platform runtime, you can use EF 6 in your new MVC 6 application instead, and target .NET 4.5.2. or 4.6

Summary

The purpose of this post was to clarify the various new pieces that will be made available to ASP.NET developers over the coming months. The next version of ASP.NET is still under active development and changes are being made all the time. In fact, just last week, after the release of CTP6, it was announced that runtime will be renamed from 'kre' to DNX.

If you want to keep up to date with the latest news about ASP.NET 5, you should watch the Community Standups every Tuesday (or whenever you like).