In this post, we will see some of the top features of ASP.NET Core 2.1.
SignalR
SignalR is coming to .NET Core. I have already written a post on how to use SignalR in .NET Core which is here but as some of the changes are going on with SignalR, some content of the post may change in the future.
SignalR for ASP.NET Core is a rewrite of the original SignalR.
Some of the improvements are as below.
- Simplified scale-out model
- New JavaScript client which has no dependency on jQuery
- New compact binary protocol based on MessagePack which dramatically reduces the wire size
- Support for custom protocols
- New streaming response model which streams the data from the server to the client
- Support for clients based on bare WebSockets
HTTPS
Security is very important nowadays. Browsers are getting more and more strict for the sites that do not have HTTPS enabled. I have already written a post on enforcing the HTTPS in the .NET Core application which is here.
As per the new announcement from .NET team, they have made HTTPS on by default and easy to configure. HTTPS middleware is also announced by the .NET team which will redirect all HTTP traffic to HTTPS.
HSTS support has also been added to the .NET Core 2.1. This post will help to understand what is HSTS.
Rich Swagger support
I have already written a post on how to use Swagger with .NET Core which is here.
As per the new announcement, we are no longer required to write different attributes to write the swagger documentation of an API.
The .NET team has added an opinionated layer that infers the possible responses based on what you’re likely to have done with your actions (you can still use attributes when you want to be explicit).
Swagger provides options for documenting the object model and customizing the UI to match your theme. Some of the highlights.
- XML comments
- API information and the description
- Data annotations
- You can describe the response types
- You can customize the UI and many more
More details here.
IHttpClientFactory
This feature is mostly like HttpClient as a service which will handle the cross-cutting concerns like caching, retry logic, timeouts, circuit breaker etc.
Some of the benefits provided by .NET team:
- Provide a central location for naming and configuring logical instances of
HttpClient
. For example, you may configure a GitHub client that is pre-configured to access GitHub and a default client for other purposes. - Codify the concept of outgoing middleware via delegating handlers in HttpClient and implementing Polly based middleware to take advantage of that.
- Manage the lifetime of
HttpClientMessageHandlers
to avoid common problems that can be hit when managing HttpClient lifetimes yourself.
.NET Core Module
ASP.NET Core Module is the module which lets you run ASP.NET Core applications on IIS. I have already written a post on how to host your application on IIS along with the basic details of .NET Core module which you can find here.
Today (without .NET Core 2.1), when IIS receives the request, it fires up the .NET process which will host your application which has some downsides as,
- The handlers are quite expensive
- If startup of the application fails, it becomes very tough to diagnose the problem
To resolve these issues, .NET team is moving that mode into the in-process mode which means your application now would be hosted on IIS process which will improve the performance almost as 6x times and error handling becomes easier.
In short, the runtime and your app both will be loaded into the IIS worker process (w3wp.exe).
Some other features Razor pages improvement
Some improvements like support for Area in Razor pages and Support for shared directory inside the Pages folder – /Pages/Shared
MVC Functional test fixture
By this, you can easily test your MVC application end to end which includes routing, filters, controllers, actions, views, and pages.
This will resolve some of the issues of testing like,
- Shadow copy off
- Look for missing .deps files
- Set working directory correctly
- Prevent assembly cross talk
- Streamlines the bootstrapping of your app on the Test Server
More details here.
Build time Razor
All the razor pages and views will compile as part of a build which will improve startup performance.
I have already written a post on the same which you can find here.
UI as a library
This feature was needed for a long time.
Take your razor pages and views -> build them as an assembly -> ship them as a package -> people can use them.
Packaging Razor pages and views as a reusable library. Views and pages in libraries will automatically be discovered and can be overridden by the application.
Identity UI package and scaffolder
We know that using readymade templates, we can add Identity code into the newly created applications but if we require Identity code into an existing application then we need to write more code.
To resolve this problem, Net Core 2.1 will provide a default identity UI implementation as a library. We just need to add a NuGet package and then we can enable default identity UI in Startup class.
There will be a new scaffolder which will help us to reuse the same repetitive code of Identity. All the scaffolded identity code would be generated in an identity specific area folder so that it remains nicely separated from your application code.
New Partial Tag Helper
Currently, there are partial views renderers like Html.Partial and Html.RenderPartial etc. But there is some limitation of above renderers.
New partial tag helper will make rendering a partial straightforward and elegant. We can specify the model using model expression syntax and the partial Tag Helper will handle setting up the correct HTML field prefix for us.
For example, if you have a partial view named _PartialViewTest.cshtml, then you can use this into another cshtml page using Partial tag helper as below.
- <partial name=“_PartialViewTest“ asp-for=“@Model[i]“ />
General Data Protection Regulation (GDPR) Compliance
Templates are updated with new privacy features.
For security - like Cookie Reason when creating a cookie and middleware that detects if the non-essential reason of cookie has been granted etc.
For Identity - like encrypting, downloading, deleting the user data.
Webhooks
Webhooks are my favorite. If you want to know bit more about the Webhooks then look at my post here. It is an old post but it can help to get basics of Webhooks.
Webhooks are a pattern where servers can provide the notifications to the applications in a decoupled way like basically HTTP request.
With 2.1, .NET Core team is porting a subset of the ASP.NET WebHooks receivers to ASP.NET Core.
They are planning to port the following receivers,
- Microsoft Azure alerts
- Microsoft Azure Kudu notifications
- Microsoft Dynamics CRM
- Bitbucket
- Dropbox
- GitHub
- MailChimp
- Pusher
- Salesforce
- Slack
- Stripe
- Trello
- WordPress
You can find more details from here.
And videos from Channel 9 here,
In the future post, we will see some more .NET Core 2.1 features. Stay tuned.
You can find my all .NET Core posts
here.
Hope it helps.