Serving Industries Worldwide

Innovative Ways - Satisfied Clientele

ASP.NET Core improvements in .NET 5


Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

 
 

asp-Core-improvements

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.

Table of Content

.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?

  1. BlazorWebAssembly performance improvements
  2. Blazor component virtualization
  3. BlazorWebAssembly pre-rendering
  4. BlazorWebAssembly browser compatibility analyzer
  5. Blazor java-script isolation and object references
  6. Custom Validation class in Blazor
  7. Blazorontoggle event support
  8. Model binding DateTime in UTC
  9. Control start up class activation
  10. 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:

  1. WebAssemblyPrerendering: -
    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.
  2. Web Assembly: -
    The component is not prerendered, includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser.
 

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.png');
}

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-Core-improvements

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.

Table of Content

.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?

  1. BlazorWebAssembly performance improvements
  2. Blazor component virtualization
  3. BlazorWebAssembly pre-rendering
  4. BlazorWebAssembly browser compatibility analyzer
  5. Blazor java-script isolation and object references
  6. Custom Validation class in Blazor
  7. Blazorontoggle event support
  8. Model binding DateTime in UTC
  9. Control start up class activation
  10. 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:

  1. WebAssemblyPrerendering: -
    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.
  2. Web Assembly: -
    The component is not prerendered, includes the marker for a Blazor Web Assembly app to make an interactive component when loaded in a browser.
 

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.png');
}

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.