Lada Borovina Kovjanić
Senior .NET Software Engineer
In November 2022, Microsoft released a new version of .NET 7, with a boost in performance and numerous new features for C#, ASP.NET Core, Blazor, .NET MAUI, Web APIs, WPF, WinForms and many others. Let’s go through the most interesting changes.
.NET 7 stays on course
.NET is Microsoft’s open-source developer platform for building various kinds of applications for different operating systems. The framework continues to develop as a unified development platform for building a wide range of applications that can run on different operating systems while making it simple for developers to learn. C# 11 is released along with the .NET 7 with great new features and improvements in performance. The new version of .NET has a lot of potential in different areas.
Source: Microsoft .NET conf 2022
Authentication is an essential part of APIs. Due to its complexity, a new version offers a simplified authentication and authorisation configuration. Simplified authentication requires just a single method call, which makes developers’ work easier.
Containers are one of the easiest ways to bundle and ship applications in the cloud on any platform, so the improvement of the .NET support for containers is very useful. The .NET 7 offers built-in support for containers, making it possible to easily create and publish containers using CLI without using external tools like Docker for desktop or other.
ASP.NET Core supports the latest protocols and standards. With the release of .NET 7 HTTP/3 protocol and Web Sockets over HTTP/2 are supported. Also, the new experimental support for WebTransport protocol is added and can be used for multiplexing streams over the same HTTP/3 connection.
Common C# code is usually shared among the projects through the Class Library as a .dll or a nuget package. ASP.NET Core Razor components and data models can be shared in a Razor Class Library so we can use them among other projects and can be consumed by Blazor server, WebAssembly and .NET MAUI clients.
For all the developers using ASP.NET that want to migrate to ASP.NET Core, there is a new tool for Visual Studio called Incremental upgrade tool that enables endpoints migration one by one, so we can maintain and develop the old version while upgrading.
Entity Framework Core 7 – what’s new?
New version of Entity Framework Core 7 was released with support for JSON columns which allows the mapping of aggregates built from types to JSON documents. The new feature provides the ability to map aggregate to a JSON column in the SQL Server database with just one method call. We can use LINQ queries on the aggregates that will be translated into SQL queries to drill down into the JSON.
Entity Framework Core 7 tracks changes to entities, and when the SaveChanges method is called, it updates altered entities in the database. EF7 introduces new method ExecuteUpdate and ExecuteDelete, which can edit or delete entities without using the change tracker and will perform more efficiently.
EF7 also improves the performance of SaveChanges and SaveChangesAsync methods that generate faster SQL queries. The new version introduces support for mapping insert, update and delete commands to stored procedures.
SQL Server connection strings in .NET 7 have the default Encrypt value set to true, in previous version the default value was set to false. That ensures the server is configured with a valid certificate and the client has to trust that certificate, otherwise an SqlException will be thrown.
Blazor team created a new feature Blazor hybrid that allows Razor components to run in a desktop application (Windows Forms), web (WPF) or a native mobile application (.NET MAUI). Razor components don’t run in the browser. They are rendered to an embedded Web View control and have access to the native device capabilities with component styles that are platform specific.
Most of the new features will work the same way across all the hosting models – Blazor server, WebAssembly or hybrid with .NET MAUI, but some of the features are hosting model specific.
QuickGrid is the new feature for all hosting models available as a preview. It doesn’t replace other grids but gives a basic set of features that will cover the most common scenarios. QuickGrid can do pagination and virtualization, so we can work with larger amounts of data with good performance.
Custom elements are another interesting new addition that enables registering Blazor components as custom elements that can be rendered in other web technologies. We can use this feature with client-side renderings like Angular, React, Vue or similar, as well as server-side rendering like PHP or Rails.
In Blazor WebAssembly, there are significant improvements in the performance of the runtime, enhancements are done in authentication giving developers more control over it. Loading progress is also a great new feature that shows the progress of app loading by default, which is very beneficial for users on a slow network connection.
From Xamarin to .NET MAUI
.NET Multiplatform Application UI framework (MAUI) is an evolution of Xamarin. It is a unified platform for building native client applications for Windows, Mac, Android and iOS with .NET.
With the release of .NET 7, MAUI is also supported for the previous version .NET 6. Developers can create applications from a single codebase that can run on Windows, Android, macOS, iOS and Tizen OS from Samsung. The most visible changes with the newly released version are performance improvements, solving layout performance problems with 51% faster rendering pages and faster scrolling. The upgrade of .NET MAUI now has everything we need to go through the develop – test – build – distribute – monitor process.
Xamarin has evolved to .NET MAUI and will receive support until May 2024. Microsoft recommends migrating applications from Xamarin Forms to .NET MAUI and from Xamarin to .NET 6 or .NET 7.
To help developers with smooth app migration, the assistant tool got upgraded to support .NET MAUI – the documentation and samples on how to migrate are still in preparation. While migrating, some changes need to be made within the project, but it is not a complete rewrite of the application.
The future development and support for .NET 7
.NET 7 is released as standard term support STS and will be supported for six months after a subsequent STS or LTS release.
.NET 8 is planned to be released in November 2023 as a long-term support LTS release that will get free support for three years. Such a schedule gives us enough time to discover fantastic new features and upgrade our applications to the newest version.
We have covered only some of the .NET 7’s amazing functionalities and solutions that will greatly benefit any developer working with it. There is plenty more to discover, so go on and play with it! Take this article as a simple guide to your own .NET 7 deep dive journey.
Want to learn more about .NET 7? Join our event in Zagreb!
Let’s meet and talk more during our event in Zagreb on Feb 16th. Alongside other .NET experts I will talk about my experiences with the latest version and how to put it in use. The seats are limited, so click the banner below and register.
Throwback to last Croatian Learn & chill
Want to know more about our event? Here you’ll find more information and a registration form.