×

iFour Logo

ASP.NET Core improvements in .NET 5

Kapil Panchal - December 24, 2020

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

  • play
  • pause
  • pause
ASP.NET Core improvements in .NET 5

ASP.NET core is a popular framework for building web apps on the .Net platform. As we know Asp.net Core is a cross-platform, provides a high-performance, and's an open-source framework for building modern, cloud-based, internetconnected apps. Asp.net Core supports the JavaScript Framework, Cross-platform supports, provides In-built Dependency Injection, MVC Architecture, and Razor syntax.

In ASP.NET core updates they have included the two new releases .NET 5.0 Release Candidate 1 and, Net 5.0 Release Candidate 2. To use it, we need the latest version of the visual studio.

.NET 5.0 includes many improvements like single file application, smaller container image, capable of JsonSerialize APIs, and set of null reference type annotation. Performance has been improved in .NET libraries in GC, and JIT. It also includes the newest version of language C# 9 and F# 5.

What’s new in this release?


  • BlazorWebAssembly performance improvements

  • Blazor component virtualization

  • BlazorWebAssembly pre-rendering

  • BlazorWebAssembly browser compatibility analyzer

  • Blazor java-script isolation and object references

  • Custom Validation class in Blazor

  • Blazorontoggle event support

  • Model binding DateTime in UTC

  • Control start up class activation

  • SignalR parallel hub invocation

And many more functionalities in Blazor and for API project.

What’s new in C# 9?


In C# 9, Records are the most important new feature. Records are as immutable classes and it has the tuple like feature. Using records, it is easy to use small types and take advantage of type safety throughout the application.

Records enable you to create immutable types. It will store a small amount of data.

The following example illustrates the example of a record. It stores the information from the login view.

 
Public record UserLogin(string user Name, string user Password);

Following class and above records are semantically similar to each other.

 
Public class UserLogin
{
Public UserLogin(string user Name, string user Password)
{ 
UserName = user Name,
UserPassword = user Password
}
Public UserName{ get; init;}
Public UserPassword{ get; init;}
}

Init is a new keyword that is an alternative to the set. Where set allows you to assign to a property at any time whereas init allows you to assign to a property only during object construction. Any type can use the init keyword.

Record equality is based on content and class equality is based on object identity. Records provide the GetHashCode() implementation which is based on record content. Records provide an IEquatable implementation and it uses the unique GetHashCode() behavior.

System.Text.Json


System. Text. Json has been also improved in .NET 5. It will improve performance, reliability, and make it easier who are familiar with Newtonsoft.json. It also supports the deserialization of JSON object to C# records which is the new C# feature we have discussed earlier.

HttpClient extension methods


JSON Serializer extensions are now uncovered on HttpClient, this method removes the complexity and takes care of a variety of scenarios. It handles the content stream and validating the content media type.

What’s new in BlazorWebAssembly?


In .NET 5 they have made improvements in Blazor Web Assembly run time performance. Blazor Web Assembly in .NET 5 is 3 times faster than Blazor Web Assembly in .NET 3.2 due to optimization in the core framework libraries. In these, string comparisons, dictionary lookups, and JSON handling are faster in .NET 5 Blazor Web Assembly than .Net 3.2.

 

Blazor Component Virtualization

Using the new built-in virtualization support, we can improve the performance of component rendering. It is the process or technique for limiting UI rendering, like when you have more rows in the table and it will show only a small subset at any given time. For that Blazor introduced the new component Virtualize that can be used to easily add virtualization to our component.

For the table component, we might use the C# foreach loop to show each item in the row.

 
 
@foreach (var forecast in forecasts)
{

}
 
Date Temp. (C) Temp. (F) Summary
@forecast.Date.ToShortDateString() @forecast.TemperatureC @forecast.TemperatureF @forecast.Summary

If in this table, we add thousands of items then it will take a bit long time to render. Instead of foreach use the Virtualize component as shown below.


                  
Date Temp. (C) Temp. (F) Summary
@forecast.Date.ToShortDateString() @forecast.TemperatureC @forecast.TemperatureF @forecast.Summary

The virtualize component calculates how many rows to be rendered based on the container height and size of the rendered items.

If you do not want to load all items into memory, so do this.

 

                
@forecast.Date.ToShortDateString()
@forecast.TemperatureC
@forecast.TemperatureF
@forecast.Summary
                

Item Provider is a delegate method that asynchronously retrieves the requested rows or items on demand.

 

Blazor Web Assembly Prerendering

For prerendering a component from a blazor web assembly the component tag helper supports the two render modes:

 

It prerenders the component into a static HTML and includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser.

The component is not prerendered, includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser.

  • WebAssemblyPrerendering: -

  • Web Assembly: -

Searching for Dedicated ASP.Net Core Web Developer ? Your Search ends here.

To set render mode open the host. Cshtml and in the render mode place the WebAssemblyPrerendered.

 

Blazor File Input support

Blazor now offers an Input File component for handling file uploads as shown below.

 

It is just like the HTML input type “file”. By default, the user can input one file and you can add more than one file using multiple attributes.

Blazor CSS isolation improvements in release Candidate 2


Blazor also supports CSS isolation in this release. The bundle name is now as per the project name like {project name}. style.css. In .NET 5.0 each bundle can be referenced from the root path.

We can also use the component specific styles which use normal wwwroot- relative paths to refer to related assets like following code.

 
.classSelector{
color:aqua;
border:dashed;
padding:2px;
background-image: url('some.webp');
}

Conclusion


We have discussed the new .NET 5.0 updates in Asp.Net core which improves the performance, component virtualization, JavaScript isolation, CSS isolation, Input file support, Custom Validation class attribute, Control start-up file activation, Open API specification (swagger), F5 experience in .NET core API, SignalR parallel hub invocation, and more. Have you noticed, mostly, everything is updated in the Blazor Web Assembly? They have focused on Blazor for more improvement and provides some components which are used to make attractive UI like CSS improvements with Bootstrap framework.

ASP.NET Core improvements in .NET 5 ASP.NET core is a popular framework for building web apps on the .Net platform. As we know Asp.net Core is a cross-platform, provides a high-performance, and's an open-source framework for building modern, cloud-based, internetconnected apps. Asp.net Core supports the JavaScript Framework, Cross-platform supports, provides In-built Dependency Injection, MVC Architecture, and Razor syntax. In ASP.NET core updates they have included the two new releases .NET 5.0 Release Candidate 1 and, Net 5.0 Release Candidate 2. To use it, we need the latest version of the visual studio. .NET 5.0 includes many improvements like single file application, smaller container image, capable of JsonSerialize APIs, and set of null reference type annotation. Performance has been improved in .NET libraries in GC, and JIT. It also includes the newest version of language C# 9 and F# 5. What’s new in this release? BlazorWebAssembly performance improvements Blazor component virtualization BlazorWebAssembly pre-rendering BlazorWebAssembly browser compatibility analyzer Blazor java-script isolation and object references Custom Validation class in Blazor Blazorontoggle event support Model binding DateTime in UTC Control start up class activation SignalR parallel hub invocation And many more functionalities in Blazor and for API project. What’s new in C# 9? In C# 9, Records are the most important new feature. Records are as immutable classes and it has the tuple like feature. Using records, it is easy to use small types and take advantage of type safety throughout the application. Records enable you to create immutable types. It will store a small amount of data. The following example illustrates the example of a record. It stores the information from the login view.   Public record UserLogin(string user Name, string user Password); Following class and above records are semantically similar to each other.   Public class UserLogin { Public UserLogin(string user Name, string user Password) { UserName = user Name, UserPassword = user Password } Public UserName{ get; init;} Public UserPassword{ get; init;} } Init is a new keyword that is an alternative to the set. Where set allows you to assign to a property at any time whereas init allows you to assign to a property only during object construction. Any type can use the init keyword. Read More: Using Linq In Mvc .net Core Record equality is based on content and class equality is based on object identity. Records provide the GetHashCode() implementation which is based on record content. Records provide an IEquatable implementation and it uses the unique GetHashCode() behavior. System.Text.Json System. Text. Json has been also improved in .NET 5. It will improve performance, reliability, and make it easier who are familiar with Newtonsoft.json. It also supports the deserialization of JSON object to C# records which is the new C# feature we have discussed earlier. HttpClient extension methods JSON Serializer extensions are now uncovered on HttpClient, this method removes the complexity and takes care of a variety of scenarios. It handles the content stream and validating the content media type. What’s new in BlazorWebAssembly? In .NET 5 they have made improvements in Blazor Web Assembly run time performance. Blazor Web Assembly in .NET 5 is 3 times faster than Blazor Web Assembly in .NET 3.2 due to optimization in the core framework libraries. In these, string comparisons, dictionary lookups, and JSON handling are faster in .NET 5 Blazor Web Assembly than .Net 3.2.   Blazor Component Virtualization Using the new built-in virtualization support, we can improve the performance of component rendering. It is the process or technique for limiting UI rendering, like when you have more rows in the table and it will show only a small subset at any given time. For that Blazor introduced the new component Virtualize that can be used to easily add virtualization to our component. For the table component, we might use the C# foreach loop to show each item in the row.   @foreach (var forecast in forecasts) { }   Date Temp. (C) Temp. (F) Summary @forecast.Date.ToShortDateString() @forecast.TemperatureC @forecast.TemperatureF @forecast.Summary If in this table, we add thousands of items then it will take a bit long time to render. Instead of foreach use the Virtualize component as shown below. Date Temp. (C) Temp. (F) Summary @forecast.Date.ToShortDateString() @forecast.TemperatureC @forecast.TemperatureF @forecast.Summary The virtualize component calculates how many rows to be rendered based on the container height and size of the rendered items. If you do not want to load all items into memory, so do this.   @forecast.Date.ToShortDateString() @forecast.TemperatureC @forecast.TemperatureF @forecast.Summary Item Provider is a delegate method that asynchronously retrieves the requested rows or items on demand.   Blazor Web Assembly Prerendering For prerendering a component from a blazor web assembly the component tag helper supports the two render modes:   It prerenders the component into a static HTML and includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser. The component is not prerendered, includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser. WebAssemblyPrerendering: - Web Assembly: - Searching for Dedicated ASP.Net Core Web Developer ? Your Search ends here. See here To set render mode open the host. Cshtml and in the render mode place the WebAssemblyPrerendered.   Blazor File Input support Blazor now offers an Input File component for handling file uploads as shown below.   It is just like the HTML input type “file”. By default, the user can input one file and you can add more than one file using multiple attributes. Blazor CSS isolation improvements in release Candidate 2 Blazor also supports CSS isolation in this release. The bundle name is now as per the project name like {project name}. style.css. In .NET 5.0 each bundle can be referenced from the root path. We can also use the component specific styles which use normal wwwroot- relative paths to refer to related assets like following code.   .classSelector{ color:aqua; border:dashed; padding:2px; background-image: url('some.webp'); } Conclusion We have discussed the new .NET 5.0 updates in Asp.Net core which improves the performance, component virtualization, JavaScript isolation, CSS isolation, Input file support, Custom Validation class attribute, Control start-up file activation, Open API specification (swagger), F5 experience in .NET core API, SignalR parallel hub invocation, and more. Have you noticed, mostly, everything is updated in the Blazor Web Assembly? They have focused on Blazor for more improvement and provides some components which are used to make attractive UI like CSS improvements with Bootstrap framework.
Kapil Panchal

Kapil Panchal

A passionate Technical writer and an SEO freak working as a Content Development Manager at iFour Technolab, USA. With extensive experience in IT, Services, and Product sectors, I relish writing about technology and love sharing exceptional insights on various platforms. I believe in constant learning and am passionate about being better every day.

Build Your Agile Team

Enter your e-mail address Please enter valid e-mail

Categories

Ensure your sustainable growth with our team

Talk to our experts
Sustainable
Sustainable
 
Blog Our insights
10 Executive Dashboard Examples for Consultants and CEOs
10 Executive Dashboard Examples for Consultants and CEOs

There is a principle behind every business. “If you don’t keep track of essentials, you won’t get clear direction, eventually causing your company to stumble.” To manage this scenario,...

How Spatial Data Analysis Improves Healthcare
How Spatial Data Analysis Improves Healthcare

Do you know when geospatial analysis took traction in healthcare? It was when John Snow, a London-based physician, used it to analyze the spread of cholera, which ultimately proved...

4 Types of Power BI Dashboards: Analytical, Strategic, Operational, and Tactical
4 Types of Power BI Dashboards: Analytical, Strategic, Operational, and Tactical

One interesting aspect you truly love about Power BI, as a CTO, is how it lets you step back and see the bigger picture of your business. Isn’t it? Without getting bogged down in minute...