Why you should learn ASP.NET Core

Introduction

A bit of History

I have been surprised by the fact that so many people are not aware of Microsoft’s open source shift over last 5 (and maybe few more) years. Lots of people are not aware of current state of .NET, .NET Core and ASP.NET Core. And I do not blame them, they have been occupied by some other responsibilities or technologies.

Before diving into ASP.NET Core and all amazing things about, let’s first take a look at the .NET framework and the current state of ASP.NET MVC.

In 2009 Microsoft released source code for ASP.NET MVC. However, not before March 2012 that it was released under Apache License 2.0, meaning that anyone can contribute and give feedback.

.NET Framework has been advancing slowly over last few years, but it’s still going, there are updates and bug fixes. This is because most of the resources have been focused on .NET Core and it has been going full speed.

Regarding ASP.NET MVC, there hasn’t been a new version of ASP.NET MVC 5 since February 2015. That is over 2.5 years. However, one might argue that there aren’t too many things to fix for that one and that community already solved most of the problems on their own.

But, there is ASP.NET Core MVC, which is already in version 2 and is steadily going for version 2.1. ASP.NET Core 2 is already mature, it is fast and it is ready for production! Let’s see why you should switch and use ASP.NET Core.

ASP.NET Core (2) has been revamped, and it is better, faster and easier to work with!

 

Into .NET Core and ASP.NET Core

.NET Core and ASP.NET Core are NOT some kind of handicapped, mutilated versions of .NET and ASP.NET. Thing is, a lot of windows only dependencies have been removed from the framework, but almost everything that might have been of use for you and that was part of those frameworks has been ported to a cross-platform NuGet package.

Let’s see why you should switch and use ASP.NET Core and ASP.NET Core MVC:

  • .NET Core is a cross-platform version of .NET, that supports almost all that .NET supported (except things like WPF, Windows Forms, Web Forms and Active Directory)
  • .NET Core and ASP.NET Core are FREE and Open Source but also they are supported by Microsoft.
  • Both ASP.NET Core and .NET Core have full attention of Microsoft and they have over 300 people employed by Microsoft working on it PLUS hundreds of community members actively contributing!
  • ASP.NET Core is cross-platform web framework built on top of .NET Core. It is built from scratch, however, a lot of old concepts and patterns are still there.
  • Both, ASP.NET Core and .NET Core are faster and easier to work with, than their predecessors.
  • If you wanna update your system and it uses Web Forms or old MVC, you should really consider ASP.NET Core MVC instead of ASP.NET MVC 5 (last updated Feb 2015)
  • C# is awesome!
  • Visual Studio is amazing

If that wasn’t enough to convince you, let’s check out all the goodies that you get by using ASP.NET Core.

Some of the amazing things in .NET Core and ASP.NET Core world

Microsoft support

Hundreds of people from Microsoft are working on .NET Core and ASP.NET Core! And there are lots of community members contributing on GitHub!

.NET Core, ASP.NET Core, Entity Framework Core, Rosyln may all be open sourced and available on GitHub but Microsoft provides official support for these products, on GitHub as well. However, just like for Visual Studio, you can still pick up the phone and call the support for any of these products. So, all these products are Microsoft supported, but .NET Core, ASP.NET Core and Entity Framework Core are completely free, open source and multi-platform, which means: no license costs.

.NET Standard – “one specification to rule them all”

NET Standard is:

  • A set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.
  • .NET Standard 2.0 is implemented by .NET Framework, .NET Core, and Xamarin. For .NET Core, this added many of the existing APIs that have been requested.
  • Version 2.0 includes a compatibility shim for .NET Framework binaries, significantly increasing the set of libraries that you can reference from your .NET Standard libraries.
  • .NET Standard will replace Portable Class Libraries (PCLs) as the tooling story for building multi-platform .NET libraries.
  • You can see the .NET Standard API definition in the dotnet/standard repo on GitHub.

If you want to know more about .NET Stanard you can check out the FAQ on GitHub.

Better, faster and easier ASP.NET Core

ASP.NET Core has been revamped. Everything is modular nowadays. And you add individual NuGet packages for all your needs. If you want to use MVC you add a NuGet package for MVC (do note that Web API is now part of MVC. If you want to use LINQ in some library, you just add it as a NuGet package. Do you want to use System.Net.Http? Add it as a NuGet package.

When you creating a new project it is much cleaner and easier to work with.

Dependency Injection is built-in and everything is built around it. When you want to use some tool and its services, you add the NuGet package and you use one of it extension methods to add the package to the ASP.NET Core’s DI container.

Configuration is built-in and also part of Dependency Injection. Use it anywhere in your code with an option to reload on changes of configuration values from sources (appsettings.json, environment variables, command line arguments, etc.). It is also easy to override, extend and customize the Configuration. No more extensive configurations in web.config, the preferred way now is appsettings.json in combination with a mix of environment variables and cmd-line args.

Logging is built-in and you get access to structured logs from the ASP.NET Core host itself to your application. It is also easy to extend and you use different and multiple sources for output. With tools like Serilog, you can extend your logging easily and save your logs to file, Azure, Amazon or any other output provider.

You configure the request and response in one method. It is achieved by using sequential series of delegates, that can either short-circuit or pass on the HTTP request to next delegate. These are known as middleware, a concept well known to people who worked with Node.js.

Another great thing about ASP.NET Core is that it is fully async, the whole pipeline is async.

Also, cold start times have been greatly improved.

.csproj

File explorer and project explorer are now in sync. For .NET Core projects, you can easily drop a file from file explorer into a project or delete it from the file system and it will be gone from the project. No more source files in a .csproj file.

You can now edit the .csproj file directly without unloading the project.

Packages

.csproj file has been cleaned up and it also serves the role of packages.config(or package.json for Node devs). That means that’s where your packages and versions will be saved.

NuGet packages are the unit of reference and they can depend on other NuGet packages, but also they can depend on projects. And as before, projects can also depend on NuGet packages and other projects. That means that projects and NuGet packages are interchangeable.

With .NET Core, you can easily turn your projects into NuGet packages, with one click on the properties.

Metapackage

If you don’t want to be bothered with the installation of Microsoft’s official ASP.NET Core packages and maintaining the versions for those packages, then this Metapackage will save you tons of time and increase your productivity!

You can add specific NuGet packages for all your needs, but with ASP.NET Core 2 in regard to NuGet packages that Microsoft ships recommended way is to use one Microsoft.AspNetCore.All meta-package. For other packages, you still use them as individual packages.

Why metapackage? Well, you get reference to bundle of packages published by Microsoft that you just might need and only packages that are actually used are being deployed

Do you need SQLite? No problems, it is in meta-package. Do you need any or all authentication packages? It is included in meta-package. Do you need CORS? It is in meta-package.

Authentication, Authorization, Kestrel, Logging, Razor, SqlServer, SqlLite, EntityFramework and tons of others. Literally, all you need is there.

It includes everything you might need for ASP.NET Core, all packages built by Microsoft. At the moment it references about 136 packages. You can see the full list on the NuGet website.

This might seem to go against that motto that everything is modular and a NuGet package. However, that is not the case!

Microsoft.AspNetCore.All only works for ASP.NET Core 2 apps and all the packages that it references are already included in Runtime Store (serves a similar purpose that GAC does for the .NET framework). Runtime Store is included with both .NET Core 2 Runtime and.NET Core 2 SDK. The beauty of this is that only packages that you actually use and reference from your code will be published. Everything else gets ignored, Runtime Store will trim all the unnecessary packages for you.

The beauty of this is that only packages that you actually use and reference from your code will be published. Everything else gets ignored, Runtime Store will trim all the unnecessary packages for you.

Kestrel

Kestrel is a cross-platform web server built for ASP.NET Core based on libuv – a cross-platform asynchronous I/O library.

It is default web server, hence it is used in all ASP.NET Core templates. It is secure enough to use it without a reverse proxy server.

It is good enough to use it without a reverse proxy server. However, you can use IIS, Nginx or Apache or something else.

Besides being cross-platform, another great advantage of Kestrel is speed. It is faaaast.

Rider

JetBrains is a company that many developers love. They released ReSharper, WebStorm, IntelliJ IDEA, PyCharm, PhpStorm, TeamCity and all other great tools.

Now imagine the power of IntelliJ, ReSharper, and WebStorm in one. I will let that sink in first. Meet Rider!

They went the step further and developed their own cross-platform .NET IDE: Rider. You can develop .NET, ASP.NET, .NET Core, Xamarin or Unity applications on Linux, Mac, and Windows.

Rider supports .NET Framework, the new cross-platform .NET Core, and Mono based projects. This lets you develop a wide array of applications including .NET desktop applications, services and libraries, Unity games, Xamarin apps, ASP.NET and ASP.NET Coreweb applications.

It is still young and in works, but it’s the best thing you will find on Mac OS and Linux.

Docker

Microsoft provides and updates Docker images for .NET Core SDK as well as for ASP.NET Core.

When creating new web applications with .NET Core you can immediately enable Docker support and you will have needed Docker files created and set up for you. You can use either Visual Studio or command line tools.

Slack

There is a Slack community where you can find a lot of great professionals, developers, enthusiasts that are rock solid with .NET, .NET Core, ASP.NET Core and anything you might need help with. Besides great developers from community, on the Slack you can also find guys like Jon Galloway (.NET Foundation director), Damian Edwards (PM of PMs on ASP.NET Team, SignalR co-creator), David Fowler(ASP.NET Core architect, SignalR co-creator), Smit Patel and some other people who are employees of Microsoft and working on these technologies.

Join the ASP.NET Core slack – click here.

 

Disclaimer

No, I don’t work for Microsoft. I just love doing C# and ASP.NET Core and I wanna clear up some things and break some prejudices about Microsoft, .NET Core and ASP.NET Core, licenses, support etc. Some people still believe that Microsoft is all about proprietary tech and that it has no business in the open-source world. This is totally wrong and so ancient. You have been living in the past, my friend. 😉

Some fun facts about Microsoft:

  • Microsoft is top open-source contributor on GitHub
  • Some amazing open-source contributors have joined Microsoft:
    • Sean Larkin – Core team member of Webpack and Angular CLI
    • John-David Dalton – Creator and main dev of Lodash
    • John Papa – open source contributor and PluralSight author, author of famous AngularJS style guide
    • Rob Eisenberg – Creator of Durandal, Aurelia, one of original core contributors on Angular (2) Router etc.
  • Microsoft is member of Linux Foundation
  • TypeScript is another great product of Microsoft. It is free and open source programming language designed for development of large applications and compiles to JavaScript
  • Visual Studio Code is one of the most popular code editors, if not the most popular one. It is FAST, open source, cross-platform, FAST (yes, fast) and extensible. It has been developed in TypeScript, NodeJS, and JavaScript
  • Visual Studio has free Community edition

 

Summary

Most important things to note:

  • .NET Core, ASP.NET Core, Entity Framework Core are all FULLY open sourced and free
  • You still get full Microsoft support for .NET Core, ASP.NET Core, Entity Framework Core
  • Amazing tooling – Visual Studio, ReSharper, Visual Studio Code, Rider, Visual Studio for Mac
  • Amazing community – join the ASP.NET / C# / ASP.NET Core Slack – click here.
  • Weekly standup on https://live.asp.net – guys who work for Microsoft discuss the future of ASP.NET Core and current state of art
  • Node.js is fast – over 400 000 requests per second (plaintext)
  • ASP.NET Core is blazing fast! – ASP.NET Core (on Linux!) itself can handle over 2 000 000 – 2 Million requests per second. ASP.NET Core MVC can handle over 1 million requests per second! (plaintext)
  • Roslyn – C# compiler is open source since 2014 and many tools are using it as a service
  • Visual Studio 2017:
    • Installation process has been revamped, you can now install the Core of VS with C# in 2 minutes on a PC with SSD and full support for ASP.NET Core in 5-10 minutes (compared to what used to take hours before)
    • Solution load time has been greatly improved
    • Visual Studio 2017 now has many new quick fixes and refactoring options built-in
    • Live unit testing inside of Visual Studio – check your code as you type it!
  • Rider – a cross-platform .NET IDE from JetBrains – company that built ReSharper, IntelliJ IDEA, Webstorm and many other great tools! It supports .NET Core 2 and ASP.NET Core 2
  • ASP.NET Core has been redesigned and there are many great things about it. Here are few of the most important ones:
    • Fully async pipeline
    • Built-in DI. Everything is added to built-in DI Container. DI itself is not for advanced scenarios, but for most of the smaller and mid-size projects, it can be enough. You can easily add a DI library on top of it (AutoFac, StructureMap, CastleWindsor etc..)
    • Built-in logging system – through all the ASP.NET Core system to your app you get structured logging that can be easily extended and you can plug in other loggers on top of it
    • Redesigned Configuration framework – Extensible, you can use multiple sources, bind it to strongly typed classes, inject it anywhere in your code, reload configuration in real-time
    • HTTPHandler and HTTPModules are gone, we are now using Middleware instead
    • You can run ASP.NET Core on .NET Framework as well
    • NO System.web, NO Global.asax, you start from Program.cs and Startup.cs
Ibrahim Šuta

Software Consultant interested and specialising in ASP.NET Core, C#, JavaScript, Angular, React.js.