Introduction to ASP.NET Core

aspnetcore-300x218

Here at Apcurium, we do our best to stay up to date on current and trending technologies. So when ASP.NET Core (formerly known as ASP.NET 5) was mature enough, we decided to make the jump and use it as part of one of our new project. The difference between v4.6 and Core are numerous. Make no mistake though, for now ASP.NET 4.6 is the more mature and feature rich version. It’s a tested and proved technology that has been used for years. ASP.NET Core’s purpose is not to replace ASP.NET 4.6 (yet!), hence why it was renamed from ASP.NET 5 to Core to avoid any confusion.

 

DNX

One of the main selling point of ASP.NET Core is that it’s multiplatform. All of this is powered by the .NET Execution Environment (DNX for short). The DNX is a (open-source) SDK as well as a runtime environment that allows the development of .NET applications that can run on either Windows, OSX or Linux. DNX can run console apps, but it was mainly built with running cross-platform ASP.NET applications in mind.

In short, DNX:

  • Simplifies the work of using .NET Core for cross-platform apps by
    • Hosting the CLR logic
    • Handling dependencies
    • Bootstrapping
  • Provides tooling for installing and managing NuGet packages

Speaking of NuGet packages, one of the big feature of .NET Core is that the framework libraries are included as part of the application as NuGet packages. The upgrades are now done in the context of a single application without impacting any other application running on the same machine. Developers are now in full control of the upgrade process.

 

Project.json

A DNX project is pretty much a folder (the folder hierarchy is the project’s hierarchy) and aproject.json file.

It defines:

  • Package dependencies
  • Target frameworks
  • Custom commands
  • Publishing scriptsScreen-Shot-2016-02-26-at-10.35.47-AM

The dependencies section is interesting, because this is where we now add the packages that we need for the application. (It’s also possible to do it via command line using the DNU utilities, but editing the project.json file is the most common way to do it). Visual Studio provides auto-completion via IntelliSense, so we don’t have to worry about remembering all those packages name and version by heart.

 

AppSettings.json

The AppSettings.json file basically replaces the web.config file from older ASP.NET projects. This is where we store the database connection string and the app settings. What is great, is that the move away to XML file to a more modern JSON file and the app settings can be strongly typed.

 

Kestrel web server

Kestrel is the web server of choice when working with ASP.NET Core. As it doesn’t rely on System.Web, it makes it a .NET cross-platform server. It’s based on libuv, a cross-platform asynchronous I/O library. It’s still possible to run our server on IIS, but it will mainly act as a reverse proxy server that manages and proxies requests to Kestrel.

Dernières publications

Laissez un commentaire