×
iFour Logo

What's New in .NET 7: A Quick Overview of Key Features and Updates

iFour Team - October 28, 2022

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

What's New in .NET 7: A Quick Overview of Key Features and Updates

Microsoft technologies have been influential and the reason behind the success of many large corporations. They employ them because of the robustness and high dependability that these platforms give while developing web applications.

Microsoft .NET 6 was the last LTS version published in November 2021. Microsoft has announced that .NET 7 would be released with significant enhancements to the system and its performance. It also includes a few latest but critical ASP.NET Core features that would incredibly help developers while custom software development.

The major focus of this version was on providing good support for cloud-native scenarios and helping developers with excellent tools for upgrading legacy apps.

Planning to hire dedicated .NET Core developers ? Contact us now.

1) What’s new in .NET 7?

Microsoft.NET has been a huge success for many enterprises. The platform enables organizations to build any sort of website/application and remains as primary choice because of its reliability, cross-platform compatibility, and robustness.

Before the final release of ASP.NET’s latest version, Microsoft offered previews for public testing. It has revealed a total of seven previews aimed at enhancing and supplementing .NET 7. Let's go through these, one by one.

2) .NET release modulation

Every Microsoft product has a life cycle that begins with its release and ends when it is no longer maintained. Then why is it necessary to know the release date? Because knowing the release dates helps you decide when to upgrade your software and make any necessary modifications. Every year in November, Microsoft releases its major .NET release, allowing developers to plan their roadmap accordingly.

3) New client source generator for SignalR

This is the new functionality that Microsoft ASP.NET Core will provide in .NET 7. Microsoft's new client source generator for SignalR may build strongly typed code based on the defined interface. This is especially true for the SignalR interface; there is no need to utilize them in weakly-typed methods when we can reuse them in the client.

With this new feature, the developer can implement an interface that contains the method and just call the method.

How to use the new client source code generator for SignalR?

To make use of this feature you just need to follow these steps -

Step – 1: Add a reference to AspNetCore.SignalR.Client.Source generator.

Step – 2: Next, add the following classes to your project:

  • HubClientProxyAttribute and
  • HubServerProxyAttribute

Step – 3: Then add a static partial class and write the static partial methods with the attributes HubServerProxy and HubClientProxy.

Step – 4: Finally, we will be using these partial methods to work with the new SignalR client source generator.

Here is an example of using partial methods.



public interface IServerHub
{
Task SendMessage(string message);
Task Echo(int i);
}

public interface IClient
{
Task ReceiveMessage(string message);
}

public class Client : IClient
{
// Equivalent to HubConnection.On("ReceiveMessage", (message) => {});
Task ReceiveMessage(string message)

{
return Task.CompletedTask;
}

}

HubConnection connection = new HubConnectionBuilder().WithUrl("...").Build();
var stronglyTypedConnection = connection.ServerProxy();
var registrations = connection.ClientRegistration(new Client());
await stronglyTypedConnection.SendMessage("Hello world");
var echo = await stronglyTypedConnection.Echo(10);

	

4) Validate errors with JSON property names

This new feature allows you to access and manually configure validation errors with property names using “SystemTextJsonValidationMetadataProvider”, thanks to Microsoft. Check out the original source for more information on using JSON property names in validation errors

Looking for an esteemed .NET development company ? Your search ends here!

Here is an example of validation errors with JSON property names.




services.AddControllers(options =>
{
options.ModelMetadataDetailsProviders.Add(new SystemTextJsonValidationMetadataProvider())
});


5) New .NET watch console output

The console output got clean and better with core and stand-out emojis. Take a look at the below reference.

Sort data - Reactjs
New dot net watch console output

6) New Minimal API improvements

This new Microsoft.NET 7 feature will improve the minimum APIs IFormFile and IFormCollection. This allows you to easily manage and upload files using IFormFile and IFormCollection. 

The next new enhancement to the Minimal API in ASP.NET Core comes to Steam and PipeRider.

In what kind of scenarios these minimal APIs would be used?

Assume you need to store data in a storage or queue provider such as Azure. In this situation, PipeRider and Steam may be used to bind the body of a request and then process it in the cloud.

However, Microsoft instructs us on three aspects to ensure the proper use of these minimum APIs:

  • The Stream can be read only once since the request body is not stored in the Buffer
  • We will reuse the underlying buffers and we discarded, Stream and PipeRider that cannot be used outside the action handler.
  • When ingesting any type of data, the Stream will always be the same object as the Body.

Microsoft brings the last update in the minimal APIs in Preview 1, and it is regarding JSON configuration.

7) Injection services in Blazor

If you want to add inject services into custom validation attributes in Blazor, then you can simply do it in the new Injection services available in Blazor. Blazor will set up the ValidationContext so that you can use it as the service provider.

Here is an example how its looks like:



public class SaladChefValidatorAttribute : ValidationAttribute
{
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        var saladChef = validationContext.GetRequiredService();

        if (saladChef.ThingsYouCanPutInASalad.Contains(value.ToString()))
        {
            return ValidationResult.Success;
        }
        return new ValidationResult("You should not put that in a salad!");
    }

}

// Simple class configured as a service for dependency injection
public class SaladChef
{
     public string[] ThingsYouCanPutInASalad = { "Strawberries", "Pineapple", "Honeydew", "Watermelon", "Grapes" };
}


Check out this source to learn more on Inject services into custom validation attributes in Blazor.

8) Razor pages and MVC views with nullable models

Microsoft has brought another interesting update in ASP.NET 7 that is focused on user experience. The primary focus is on improving the checks and ability of models, Microsoft Implemented the nullable view for checks that are of the null state of any ASP.NET Core application.

However, there are no examples to demonstrate these enhancements. Let us hope that Microsoft will continue to provide new features and provide in-depth explanations like the ones previously revealed.

Let’s wait for the new Microsoft ASP.NET 7 features and the next version that is quicker than ASP.NET 7.

Conclusion

Microsoft introduces new features and functionalities in the latest edition of ASP.NET Core for .NET 7. Every Microsoft .NET update provided some new features and services that gave users a distinct experience and grew the Microsoft universe throughout time. In this blog, we looked at what's new in ASP.NET 7 and how these features could help developers in simplifying their web development efforts.

What's New in .NET 7: A Quick Overview of Key Features and Updates Table of Content 1.What’s new in .NET 7? 2..NET release modulation 3.New client source generator for SignalR 4.Validate errors with JSON property names 5.New .NET watch console output 6.New Minimal API improvements 7.Injection services in Blazor 8.Razor pages and MVC views with nullable models 9.Conclusion Microsoft technologies have been influential and the reason behind the success of many large corporations. They employ them because of the robustness and high dependability that these platforms give while developing web applications. Microsoft .NET 6 was the last LTS version published in November 2021. Microsoft has announced that .NET 7 would be released with significant enhancements to the system and its performance. It also includes a few latest but critical ASP.NET Core features that would incredibly help developers while custom software development. The major focus of this version was on providing good support for cloud-native scenarios and helping developers with excellent tools for upgrading legacy apps. Planning to hire dedicated .NET Core developers ? Contact us now. See here 1) What’s new in .NET 7? Microsoft.NET has been a huge success for many enterprises. The platform enables organizations to build any sort of website/application and remains as primary choice because of its reliability, cross-platform compatibility, and robustness. Before the final release of ASP.NET’s latest version, Microsoft offered previews for public testing. It has revealed a total of seven previews aimed at enhancing and supplementing .NET 7. Let's go through these, one by one. 2) .NET release modulation Every Microsoft product has a life cycle that begins with its release and ends when it is no longer maintained. Then why is it necessary to know the release date? Because knowing the release dates helps you decide when to upgrade your software and make any necessary modifications. Every year in November, Microsoft releases its major .NET release, allowing developers to plan their roadmap accordingly. 3) New client source generator for SignalR This is the new functionality that Microsoft ASP.NET Core will provide in .NET 7. Microsoft's new client source generator for SignalR may build strongly typed code based on the defined interface. This is especially true for the SignalR interface; there is no need to utilize them in weakly-typed methods when we can reuse them in the client. With this new feature, the developer can implement an interface that contains the method and just call the method. Read More: What is new in .NET 5? How to use the new client source code generator for SignalR? To make use of this feature you just need to follow these steps - Step – 1: Add a reference to AspNetCore.SignalR.Client.Source generator. Step – 2: Next, add the following classes to your project: HubClientProxyAttribute and HubServerProxyAttribute Step – 3: Then add a static partial class and write the static partial methods with the attributes HubServerProxy and HubClientProxy. Step – 4: Finally, we will be using these partial methods to work with the new SignalR client source generator. Here is an example of using partial methods. public interface IServerHub { Task SendMessage(string message); Task Echo(int i); } public interface IClient { Task ReceiveMessage(string message); } public class Client : IClient { // Equivalent to HubConnection.On("ReceiveMessage", (message) => {}); Task ReceiveMessage(string message) { return Task.CompletedTask; } } HubConnection connection = new HubConnectionBuilder().WithUrl("...").Build(); var stronglyTypedConnection = connection.ServerProxy(); var registrations = connection.ClientRegistration(new Client()); await stronglyTypedConnection.SendMessage("Hello world"); var echo = await stronglyTypedConnection.Echo(10); 4) Validate errors with JSON property names This new feature allows you to access and manually configure validation errors with property names using “SystemTextJsonValidationMetadataProvider”, thanks to Microsoft. Check out the original source for more information on using JSON property names in validation errors Looking for an esteemed .NET development company ? Your search ends here! See here Here is an example of validation errors with JSON property names. services.AddControllers(options => { options.ModelMetadataDetailsProviders.Add(new SystemTextJsonValidationMetadataProvider()) }); 5) New .NET watch console output The console output got clean and better with core and stand-out emojis. Take a look at the below reference. New dot net watch console output 6) New Minimal API improvements This new Microsoft.NET 7 feature will improve the minimum APIs IFormFile and IFormCollection. This allows you to easily manage and upload files using IFormFile and IFormCollection.  The next new enhancement to the Minimal API in ASP.NET Core comes to Steam and PipeRider. In what kind of scenarios these minimal APIs would be used? Assume you need to store data in a storage or queue provider such as Azure. In this situation, PipeRider and Steam may be used to bind the body of a request and then process it in the cloud. However, Microsoft instructs us on three aspects to ensure the proper use of these minimum APIs: The Stream can be read only once since the request body is not stored in the Buffer We will reuse the underlying buffers and we discarded, Stream and PipeRider that cannot be used outside the action handler. When ingesting any type of data, the Stream will always be the same object as the Body. Microsoft brings the last update in the minimal APIs in Preview 1, and it is regarding JSON configuration. Read More: 13 Important .Net Core Libraries that Every .Net Core Developer Should Know 7) Injection services in Blazor If you want to add inject services into custom validation attributes in Blazor, then you can simply do it in the new Injection services available in Blazor. Blazor will set up the ValidationContext so that you can use it as the service provider. Here is an example how its looks like: public class SaladChefValidatorAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var saladChef = validationContext.GetRequiredService(); if (saladChef.ThingsYouCanPutInASalad.Contains(value.ToString())) { return ValidationResult.Success; } return new ValidationResult("You should not put that in a salad!"); } } // Simple class configured as a service for dependency injection public class SaladChef { public string[] ThingsYouCanPutInASalad = { "Strawberries", "Pineapple", "Honeydew", "Watermelon", "Grapes" }; } Check out this source to learn more on Inject services into custom validation attributes in Blazor. 8) Razor pages and MVC views with nullable models Microsoft has brought another interesting update in ASP.NET 7 that is focused on user experience. The primary focus is on improving the checks and ability of models, Microsoft Implemented the nullable view for checks that are of the null state of any ASP.NET Core application. However, there are no examples to demonstrate these enhancements. Let us hope that Microsoft will continue to provide new features and provide in-depth explanations like the ones previously revealed. Let’s wait for the new Microsoft ASP.NET 7 features and the next version that is quicker than ASP.NET 7. Conclusion Microsoft introduces new features and functionalities in the latest edition of ASP.NET Core for .NET 7. Every Microsoft .NET update provided some new features and services that gave users a distinct experience and grew the Microsoft universe throughout time. In this blog, we looked at what's new in ASP.NET 7 and how these features could help developers in simplifying their web development efforts.

Categories

Ensure your sustainable growth with our team

Talk to our experts
Sustainable
Sustainable
 

Blog Our insights

.NET Core 6 improvements in LINQ: An essential guide for 2023
.NET Core 6 improvements in LINQ: An essential guide for 2023

Table of Content 1.What is .NET Core 6? 2.What are the new features of .NET Core 6? 3.What is LINQ? What is the purpose of LinQ? 4.How to use LINQ with .NET Core? 5.How...

What's New in .NET 7: A Quick Overview of Key Features and Updates
What's New in .NET 7: A Quick Overview of Key Features and Updates

Table of Content 1.What’s new in .NET 7? 2..NET release modulation 3.New client source generator for SignalR 4.Validate errors with JSON property names 5.New .NET...

 Real-time communication using SignalR and .NET Core: A step-by-step guide
Real-time communication using SignalR and .NET Core: A step-by-step guide

Table of Content 1.Introduction to SignalR 2.Overview of ASP.NET Core SignalR 3.How SignalR works in ASP.NET Core? 4.What are the advantages of SignalR? 5.How...