- Modern Web Development with ASP.NET Core 3
- Ricardo Peres
- 1113字
- 2021-06-18 18:35:54
What's new since version 2.0?
Let's see what is new in version 2.0 by going through the following sections.
ASP.NET Core 2.1
ASP.NET Core 2.1 was released on the web on May 30 2018. It doesn't contain a large number of breaking changes or fantastic new features, but I would highlight the following ones.
SignalR
SignalR, the real-time communication library for ASP.NET Core, finally made it out of prerelease. It has lots of goodies that didn't exist in pre-Core versions, and we will cover it in its own chapter.
Razor class libraries
It is now possible to package Razor UI files (.cshtml) as NuGet packages. This opens the door to lots of interesting possibilities. There will be more on this in the chapter about component reuse.
Razor pages improvements
Razor pages, introduced in ASP.NET Core 2.0, now also support areas and have a couple of additional features. We will go through them in the chapter on views.
New partial tag helper
There's a new <partial> tag helper that provides a somewhat cleaner alternative to RenderPartial. Again, it will be discussed in the chapter about component reuse.
Top-level parameter validation
In previous versions of ASP.NET Core, you had to explicitly check the validation status of your model, usually through a call to ModelState.IsValid. Now, this is no longer the case, and the validation of parameters using any validator is configured is done automatically. We'll talk more about this in the chapter dedicated to forms and models.
Identity UI library and scaffolding
Together with the new Razor UI class libraries, Visual Studio now has support for scaffolding, and ASP.NET Core Identity is a good candidate for this. What this means is that if we select ASP.NET Core Identity as the authentication provider, we can cherry pick the UI components we're interested in (login page, login status, and so on) and provide the rest. This will be covered in the chapter dedicated to security.
Virtual authentication schemes
There's a new mechanism by which we can abstract (and possibly combine) different authentication providers: it's called virtual authentication schemes, and we will talk about it in the chapter on security.
HTTPS by default
What else can I say? HTTPS is now the default, but configurable through the Visual Studio wizard. Hopefully, it will both make your applications more secure and prevent some subtle problems that only arise when deploying to production. It will be covered in the chapter on security.
GDPR-related template changes
The Global Data Protection Regulation (GDPR) imposed a number of constraints when it comes to tracking users and storing their data. The new Visual Studio templates and the ASP.NET Core 2.1 APIs introduced some changes related to cookie tracking and explicit user consent. We will talk about all these in the security chapter.
MVC functional test improvements
Functional (or integration) tests are now easier to set up because .NET Core 2.1 makes some assumptions that are generally ok. There will be more on this in the chapter on testing.
API conventions and supporting types
There have been some improvements in regards to providing metadata and discoverability for API endpoints, all of which will be covered in a new chapter about API controllers and actions.
Generic host builder
This may not be too important for ASP.NET Core developers, but there's a new host builder that can be used to build non-HTTP endpoints. Because this is too specific, we won't talk about it in this book.
Updated SPA templates
There are new templates for single-page applications (SPAs) available for some of the most popular JavaScript frameworks: Angular, React, and React with Redux. I will (briefly) cover these in the chapter about client-side development.
ASP.NET Core 2.2
ASP.NET Core 2.2 was released in December 2018. Some of the changes are outlined in the following sections.
API code analyzers
Visual Studio can now automaticallyadd attributes that describe the return types and codes for API actions based on conventions.
Health check API
Health check APIs were previously available as prerelease code, but are now available as stable and fully supported checks for multiple conditions.
Endpoint routing
There is now a faster routing mechanism that also allows the inferring of the current route much earlier in the pipeline. It also includes parameter transformers.
Problem details (RFC 7807) support
There is new support for the implementation of RFC 7807 problem details for representing API errors.
ASP.NET Core 3.0
ASP.NET Core 3.0 was released in September 2019. Here are some of its biggest changes.
C# 8.0
Together with .NET Core 3.0, Visual Studio 2019 was updated to support the new language features of C# 8.0.
.NET Standard 2.1
The new .NET Standard was also released, with a much greater API surface.
Blazor
Blazor (server hosting model) is now included with .NET Core 3.
Built-in JSON support
.NET now features its own JSON library, System.Text.Json.
HTTP/2 support
HttpClient now supports HTTP/2 and is enabled by default in Kestrel.
gRPC
gRPC for .NET has been released. Visual Studio and dotnet now have templates for gRPC.
IdentityServer integration
Authentication is now capable of integrating with IdentityServer out of the box.
Endpoint routing
Endpoint routing is now the default.
Migrating to ASP.NET Core 3.x
Updating a project to version 3 should be as simple as updating the TargetFramework property of the .csproj files to contain netcoreapp3.0 (or netcoreapp3.1, for .NET Core 3.1) instead of netcoreapp2.0 and removing any references to Microsoft.AspNetCore.App. It is also mandatory to remove DotNetCliToolReference, as it is deprecated and its purpose replaced by global tools. Of course, when Visual Studio asks you to update the NuGet packages of your solution, you should do it to use the latest features.
Version set
Some features of ASP.NET Core will only be available if you explicitly ask for them. This is done by calling theSetCompatibilityVersionextension method:
services .AddMvc() .SetCompatibilityVersion
(CompatibilityVersion.Version_3_0);
The values you can pass to theSetCompatibilityVersionmethod are as follows:
- Latest: Use the latest features (at the time of the writing of this book, version 3)
- Version_2_0: Use only the subset supported as of ASP.NET Core 2.0
- Version_2_1: Use the features introduced in version 2.1
- Version_3_0: Use the features of version 3
Because we want to explore all features available to ASP.NET Core, let's call it with eitherLatestorVersion_3_0. If you don't specify a value, it will default to the latest major version: 3.
Let's now move on to look at some tools that will be covered in more depth in the two appendices at the end of the book.