…or learn the lingo and sound like an ASP.NET 5 expert
So you know ASP.NET like the back of your hand, or so you think, until you hear grunt this, and bower that, and you realize that nothing has changed but EVERYTHING, and all you can do is just sit there and nod like Joey in friends.
If you don’t have time to grow a beard, or go through the Intro to ASP.NET 5 course, but still want to hang out with the cool guys, here is the cliff notes version. Just enough to be conversational.
5 quick facts about ASP.NET 5
In short, what has happened with ASP.NET 5 is that it is a new incarnation of ASP.NET based on a couple of big things that have happened with the web lately. ASP.NET 4.5 still lives on side-by-side with 5.
1. It is open source – You can read, branch and contribute to both asp.net and the underlying framework DNX Core, along with a lot of other parts of .net like the ROSLYN compiler. You can also contribute to the docs, and/or participate in the bi-weekly community standup.
2. It is cross platform – earlier ASP.NET was tightly coupled with IIS, but now all you need is a web server that implementsOWIN like the cross-platform development webserver Kestrel, or you can self-host with WebListener. DNX Core is the cross platform .net runtime that lets you run .net apps on Linux or Mac, in the cloud or on prem and you can write the app with your choice of editor/IDE whether it is Visual Studio, Visual Studio Code, Notepad, Sublime or something else.
3. It is modular – when you create an asp.net web forms app or ASP.NET MVC app you no longer have to include all of ASP.NET, you just pick and choose the parts you like. If you don’t need authentication, then don’t include it. The modularity means that the footprint is smaller and with less things in the pipeline everything is faster.
4. It’s fast – The ASP.NET team takes the performance thing very seriously, benchmarking this and that. But it is not only fast performance wise, the dev cycle is also faster. It has now been shortened from save-build-browse to save-browse, huge improvement YAY!
5. It is built for the cloud – with features like environment based configuration, and hiding client secrets so they don’t accidentally end up on GitHub. Because it is modular you can also do things like replace the normal asp.net cache with Redis.
Now you could either use something like AngularJS to write the whole application and just use ASP.NET Web API to fetch the data. Or you can mix and match ASP.NET MVC and Angular, where ASP.NET MVC could be used to route between multiple smaller SPAs and then you could use Angular routing inside the individual SPAs.
To make all this jive together we need to use a few tools:
To get started, you can actually create your ASP.NET 5 project by hand. The only thing that is really needed for a DNX core project is a project.json file and a startup.cs.
The project.json file is where you define your project and add in all your dependencies (watch the magic in the references section when you add a dependency and save). The startup.cs file has two important methods, ConfigureServices where you add in the services you are going to use (like MVC), and Configure, where you add them to the pipeline by calling the Use method.
That is basically the gist of it, but phew… that was a slew of words and tools and technologies that until recently used to be gibberish to me. A lot of them have been known for a long time by people that develop for the mean stack (MongoDB, Express, Angular, Node.JS) but it is not until now that they have been properly married with ASP.NET and the MS stack.
Oh, so many new words, my brain is exploding…
DNX – DNX is short for .NET execution engine. There are two main flavors, DNX 4.5.X (the full framework) and DNX Core 5.0 (the light-weight open source .NET version that also runs on Linux and Mac). DNX Core contains almost everything but is missing a few Windows namespaces like System.Drawing for example.
OWIN – Open Web Interface for .NET – a standard interface between .net web servers and web applications. Earlier, ASP.NET was tightly coupled with IIS. The purpose of OWIN is to break this relationship so that if you have a web server that implements OWIN correctly you can run ASP.NET on that web server. It also allows for more modularization so that you can plug and play things like MVC or authentication.
Self-hosting – If you want to avoid the overhead of hosting a Web API in IIS and want something more lightweight, you can host it in your own process, i.e. self-hosting. Self-hosting can also refer to a compiler that is written in the language it compiles, like the Roslyn C# compiler.
WebListener – a self-host ASP.NET 5 web server available on NuGet
Kestrel – a cross platform ASP.NET 5 development web server available on NuGet
MVVM – Model View ViewModel – a common pattern for apps where you separate the code for a page into 3 separate layers. View is the UI for the page, Model is the data, and ViewModel is an interface between the View and the Data with logic that massages the data so that it fits the view.
Sample Less file
Sample Sass file
NPM – NPM (Node Package Manager) is like NuGet for client-side stuff. Add an NPM configuration file (package.json) to your ASP.NET 5 app and load in the proper references by adding them to the devDependencies section. When you save the file you’ll see them show up under References/NPM. Typical things you would download with NPM are Grunt or Gulp or Bower.
Sample package.json file
Bower – Bower is also like NuGet for web stuff. Similar to NPM you add a bower configuration file (bower.json) to your app. The libraries will be downloaded to the wwwroot/lib folder by default. The * here means we will download the latest version of angular.
The Grunt way:
The Gulp way:
Yeoman/Yo – Yo is a scaffolding tool, together with the OmniSharp ASP.NET generator (generator-aspnet) that you can download with npm, it lets you quickly create a new empty asp.net 5 app where you don’t have Visual Studio (like on Mac or Linux).
Hopefully that should be enough to make you a little bit more comfortable with the hipster crowd, but if all else fails, just start mumbling about some obscure Powershell cmdlet and they will all dissapear.