ASP.NET C# MVC Core

Why I am really excited about new ASP.NET and C#

Microsoft is coming out with a bunch of new features that are make me very glad to be a .NET-oriented developer. The ASP.NET vNext platform looks like it is going to be a solid improvement to the environment; no longer will users be tied to IIS or Visual Studio and I anticipate some strong VS competitors coming out with these additions and the official support of Mono. Additionally, the C# 6.0 features are going to make some small changes that will make big impacts.

Roslyn

Roslyn is an open-source .NET compiler platform that will be allowing a ton of language updates that will be coming around with C# 6.0. Since it is also cross-platform, can run using Mono (the open-source implementation of .NET), and will be working side-by-side with the self-server ASP.NET offers, running a .NET web app on a Linux or Mac server is reasonably possible.

Language Change: Null propagation operator

This change adds the operator ‘?.’ in place of ‘.’ to access properties that could possibly be null. So for example, instead of doing this:

if (person != null && person.Address != null && person.Address.City != null) { … }

you can simply do…

if (person?.Address?.City != null) { … }

Since I use Entity Framework relationships a lot, I am really excited about this feature. I am tired of writing null check and null check…

Language Change: Primary constructors and Auto-property initializers

These two features will allow you to setup basic class construction simpler than before. So for example, when we currently do the following:

public class Person {
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public Address Address { get; set; }

 public Person(string firstName, string lastName) {
  FirstName = firstName;
  LastName = lastName;
 }
 public Person(string firstName, string lastName, string city, string state) {
  FirstName = firstName;
  LastName = lastName;
  Address = new Address(city, state);
 }
}

Instead, you can do this now:

public class Person(string firstName, string lastName) {
 public string FirstName { get; set; } = firstName;
 public string LastName { get; set; } = lastName;
 public Address Address { get; set; }

 public Person(string city, string state) : this(firstName, lastName) {
  Address = new Address(city, state);
 }
}

RyuJIT

RyuJIT is a just-in-time compiler that will allow developers to no longer have to stop debugging and re-build; instead, you simply save and refresh. At last, the workflow I love with dynamic languages like Python and PHP (though it already exists with Java, such as in Java Play) is now in ASP.NET. Stopping and rebuilding is, what, a 3 second process? That happens constantly, and builds up to plenty of time and blown concentration.

Self-hosting Applications

No longer are ASP.NET applications confined to IIS and Windows Servers. Now, ASP.NET MVC has a self-hosting tool. This is done using a new Startup.cs file, and will boot up the service:

using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;

public class Startup
{
 public void Configure(IBuilder app)
 {
  app.UseServices(services =>
  {
   services.AddMvc();
  });

  app.UseMvc(routes =>
  {
   routes.MapRoute(
   name: "Default",
   template: "{controller=Home}/{action=Index}/{id?}");
  });
 }
}

There are a ton of more features in the new ASP.NET MVC framework and C# language that will make developers (well, me, anyways) much more productive.

Leave a Reply

Your email address will not be published. Required fields are marked *