This article is more than 1 year old
Is this an ASP.NET Core I see before me? Where to next for Microsoft's confusing web framework...
Too many choices?
Microsoft's ASP.NET Core, a web application framework (or more accurately, a family of frameworks), has made strides in performance and innovation, but its rapid development has resulted in a bewildering range of choices facing developers.
The original ASP.NET was launched simultaneously with .NET itself, way back in 2002, co-developed by Microsoft’s Scott Guthrie and Mark Anderson. It was a replacement for the COM-based Active Server Pages. Perhaps the best and worst thing about ASP.NET 1.0 was the form-based programming model that (somewhat) handled state management for you, making it an easier transition for desktop developers, but with downsides in areas like unit testing, responsive user interfaces, and compatibility with modern JavaScript libraries. Now called web forms, this approach is still popular, but limited to the Windows-only .NET Framework.
In early 2009 Microsoft launched ASP.NET MVC, a new framework based on the model-view-controller pattern. It had many advantages over web forms, including better performance, easy integration with JavaScript, amenable unit testing, and a cleaner programming model. Although it was widely adopted in the .NET community, some developers preferred to stick with the mature web forms approach. Further confusing matters, it is possible to combine MVC and web forms, by using MVC routing with web forms pages.
As ASP.NET MVC evolved, Microsoft developed the Razor syntax for View pages. Razor lets you combine C# code and HTML mark-up with minimal ceremony. Razor was initially used for ASP.NET MVC but soon took on a life of its own, with support for projects that use Razor pages but without the MVC pattern.
Then came .NET Core and ASP.NET Core, first fully released in 2016, Microsoft's official cross-platform and open source implementation of .NET. The company implemented ASP.NET Core MVC, but not web forms.
To Blazor with you
In 2018, a new approach called Blazor joined the fray. Blazor began life with the Xamarin (.NET for mobile and Mac) team at Microsoft, who were working on compiling the Mono .NET runtime to WebAssembly. The name is a combination of Browser and Razor. The initial idea was to have a framework for single page applications (SPAs) written in C# and running in the browser. Developers could write C# everywhere, as opposed to mixing C#, JavaScript and perhaps TypeScript. Visual Studio, the primary tool for developing with ASP.NET, is a much better editor for C# than it is for JavaScript.
Blazor was released as part of .NET Core 3.0 in September 2019, by which time it had somewhat changed shape. The initial release is for Blazor server-side applications, which does not use WebAssembly at all. Instead, Razor components run on the server and update the browser user interface via SignalR, Microsoft's framework for real-time communications.
Blazor WebAssembly is in preview. The code the developer writes for Blazor Server or Blazor WebAssembly is pretty much the same, but the outcome is very different. As the documentation notes, with Blazor Server, "Higher latency usually exists. Every user interaction involves a network hop." Blazor Server also has advantages, with smaller download size and no requirement for WebAssembly support, but the WebAssembly option looks more attractive for most scenarios.
There is also ASP.NET Web API, a framework for building REST APIs with models and controllers adapted from ASP.NET MVC, which is suitable for serving data to mobile as well as web applications.
Strong features of ASP.NET Core are that it is cross-platform, well suited to container deployment, and easily tested. Another key feature is dependency injection, where classes do not directly create instances of the service objects on which they depend, but have them passed to them, usually in the constructor. This achieves loose coupling, a good principle but one which can be confusing for beginners. Tooling for ASP.NET Core is flexible, a far cry from the days when developing outside Visual Studio was painful. Today you can also use Visual Studio for the Mac, the cross-platform Visual Studio Code, or any text editor.
Microsoft's web platform is not as confusing as its desktop platform, but does present developers with a confusing array of choices. One of them, ASP.NET MVC, is not quite deprecated but heading in that direction. Microsoft's documentation now says that: "For new development, we recommend Razor Pages over MVC with controllers and views."
In fact, the documentation authors cannot keep up with all the permutations. The page referenced above, a tutorial for data access with ASP.NET MVC, states that "There is a Razor Pages version of this tutorial. Each tutorial covers some material the other doesn't."