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.
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
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."
Steve Gordon, a senior .NET developer at Brighton-based Madgex, which develops recruitment software, is also a .NET trainer and has been using ASP.NET since its first introduction. He now uses ASP.NET Core and says "it's a very efficient product to work with, we can build out microservices very quickly and very easily with it."
He says the platform is not so confusing if you have followed it through the various changes. What does he think of Blazor? "I can see that it might be an easier onboarding experience for someone experienced in building single-page apps with Node.js to make a transition, as well as to help .NET developers that are more familiar with C# to continue coding and working in the browser," he told The Register.
One of the issues with ASP.NET Core is that new releases bring breaking changes. Gordon says that part of the solution for enterprise developers is to note Microsoft's different support models for long term support (LTS) releases. For example, .NET 3.0 is not an LTS release, but .NET 3.1 is. The policy is laid out here. "I've seen developers fall into the trap that they adopt the latest current release not realising that the support will run out soon, where Microsoft has historically supported things much longer."
Microsoft does tend to tangle ASP.NET Core with another of its frameworks, the database object-relational mapping technology called Entity Framework EF Core. At its best, it is like magic: developers simply write C# classes to represent data, and EF generates the tables and lets developers work with C# objects rather than having to think about the database. There are a number of snags, though. If you take a naïve approach to using EF Core, performance often becomes a problem, and the simplicity tends to dissolve where relationships are complex. It may not work well if you use databases other than Microsoft's SQL Server, for which it is a kind of marketing tool.
The issue is nicely expressed here, by DevOps engineer Michael Hoagland: "If you want to let your applications actually use even a fraction of what you’re paying those huge licensing fees for, stop constraining SQL to an EF driven hellish wasteland of something little better than SELECT *."
Hoagland argues that EF can be used efficiently, but that this is rarely the case, in part because Microsoft's documentation leads developers down the wrong path.
Developers in search of better performance may wish to look at Dapper, a thin object mapper for .NET that requires developers to know their SQL, but in return delivers much faster results.
StackOverflow survey shows that while developers enjoy working with ASP.NET, it doesn't appeal strongly to those not yet using it
The most recent StackOverflow technology survey shows ASP.NET used by 26.3 per cent of respondents, scoring 64.9 per cent for "most loved" and 35.1 per cent for "most dreaded." These are not bad figures, but most telling is that the platform scores only 3.7 per cent under "most wanted,” supporting a suspicion that while Microsoft’s move towards open source and cross-platform with .NET Core and ASP.NET Core have helped developers like Gordon stay on board with the company’s web platform, it has not been so successful in attracting new developers from elsewhere. One of the issues, perhaps, is that Microsoft tends to present it as part of a package including Entity Framework, SQL Server and even Azure. That must be good for product adoption, but does conflict with its effort to appeal to a wider community. ®