.NET 9.0 Preview 7 brings AOT compilation for SignalR services

0
30
.NET 9.0 Preview 7 brings AOT compilation for SignalR services


Microsoft has released the seventh preview version for .NET 9.0 – with new features for native AOT. This cutting-edge compiler for .NET has been available in .NET since version 7.0. There it initially worked only for console applications. .NET 8.0 added ASP.NET Core-based Web API and gRPC services as well as worker services. Since Preview 7 of the upcoming .NET version 9.0, which was released this week, SignalR services with native AOT and trimming (tree shaking) are also possible when using the Just-in-Time compiler.

Advertisement


However, SignalR (like other types of applications) has functional limitations related to trimming and AOT compilation. Strictly typed hubs are not allowed, nor are return types IAsyncEnumerable And ChannelReader. There are only return types for asynchronous SignalR operations Task, Task, ValueTask And ValueTask Permission.

Data transfer is typically JSON serialization with Microsoft’s JSON serializer System.Text.Json and associated source generators possible; more compact SignalR formats such as message packs are initially excluded.

in the readme document Regarding the new features in ASP.NET Core 9.0 Preview 7, Microsoft also mentioned that OpenAPI metadata generation with the NuGet package “Microsoft.AspNetCore.OpenApi”, which has been available since .NET 9.0 Preview 4, now works with trimming and native AOT. However, tests previously showed that it already worked with Preview 5. In Preview 7, Microsoft has changed the existing option to integrate OpenAPI transformers: instead UseTransformer() There are now separate methods for documents, schemas, and operations: AddDocumentTransformer(), AddSchemaTransformer() And AddOperationTransformer(),

An implementation for Open ID Connect is built into ASP.NET Core, which you can use AddOpenIdConnect() Active, used in the Pushed Authorization Request (PAR) standard since .NET 9.0 Preview 7 RFC 9126. However, developers can disable PAR if they wish:

builder.Services
    .AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie()
    .AddOpenIdConnect(oidcOptions =>
    {
        // Other provider-specific configuration goes here.

        // The default value is PushedAuthorizationBehavior.UseIfAvailable.
        oidcOptions.PushedAuthorizationBehavior = PushedAuthorizationBehavior.Disable;
    });

ASP.NET Core 9.0 Preview 7 also allows for the first time the repeal of keys, which has been integrated since .NET Core 1.0 Data Protection API. A new method has come for this DeleteKeys() In the interface IDeletableKeyManager. Microsoft mentions that deleting keys can be useful for services that have been running for a very long time. Data encrypted with it can no longer be used. So Microsoft positions itself clearly: “Our guidance is that data protection keys should not be deleted.”

But ExceptionHandlerMiddleware Developers can now customize the HTTP status codes that appear in HTTP headers and in the case of uncaught runtime errors Problem description according to RFC 9457 Goes to the customer:

builder.Services.AddProblemDetails();
…
app.UseExceptionHandler(new ExceptionHandlerOptions
{
    StatusCodeSelector = ex => ex is ApplicationException
        ? StatusCodes.Status503ServiceUnavailable
        : StatusCodes.Status500InternalServerError,
});

In ASP.NET Core Minimal Web API, calling ProducesProblem() And ProducesValidationProblem() even after that MapGroup()i.e. permission is granted to entire groups of routes. In addition, developers can ProducesProblem() And ProducesValidationProblem() Data is no longer just a type IDictionarybut also as a set of types IEnumerable> Hand it over. The following list creates the JSON response shown in the image below.

(HttpGet("/Fehler/Machen"))
public Results>, ProblemHttpResult> FehlerMachen2()
{
 var timestamp = DateTime.Now;
 var logId = Guid.CreateVersion7(timestamp: timestamp);
 var problemData = new List> { new("LogId", logId), new("Timestamp", timestamp) };
 return TypedResults.Problem("Diese WebAPI-Operation hat einen schwachen Moment.", extensions: problemData);
}

Listing: Controller-based Web API that returns an error with its own data in the issue description

JSON response of the above list

(Image: Dr. Holger Schwittenberg)

ASP.NET Core provides metrics for the Open Telemetry API. Previously these were active for all endpoints. In ASP.NET Core 9.0 Preview 7, developers can now exclude individual endpoints from metrics for the first time by calling a new method DisableHttpMetrics() or use the new annotations (DisableHttpMetrics) on Web API controller classes and individual actions. This is useful for endpoints that are called frequently and only for diagnostic purposes, for example

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHealthChecks();

var app = builder.Build();
app.MapHealthChecks("/apicheck").DisableHttpMetrics();
app.Run();

Comment (DisableHttpMetrics) Developers can use not only Web APIs but also gRPC services and SignalR Hubs.

Since .NET version 8.0, named pipe services have also become possible with the Kestrel server process integrated into ASP.NET Core. This method is now provided in .NET 9.0 CreateNamedPipeServerStream() Allows you to customize individual named pipe endpoints, such as setting the buffer size. Kestrel also provides a better metric: in the metric kestrel.connection.duration Users now also receive information about the reason for connection loss, for example timeout, too much data, or failed TLS handshake.




(Image: Dmytro Vikarchuk/Shutterstock))

In Online Conference BetterCode() .NET 9.0 On November 19, 2024 by iX and dpunkt.verlag, .NET experts from www.IT-Visions.de will present a ready-made version of .NET 9.0 using practical examples. These include the .NET 9.0 SDK, C# 13.0, ASP.NET Core 9.0, Blazor 9.0, Windows Forms 9.0, WPF 9.0, WinUI, innovations in .NET MAUI 9.0 and the integration of artificial intelligence into .NET applications. Program Offers six lectures, one discussion, and six workshops.

There are tickets Available at an introductory price,

In addition to many improvements to ASP.NET Core, most of the improvements in Preview 7 are to the cross-platform UI framework .NET MAUI (Multi-Platform App UI), which did not receive many innovations in earlier preview versions.

with the new control a special form of control Developers can integrate any single-page web app with HTML, CSS and JavaScript into the .NET MAUI interface and interact with this content. Previously it was per Already possible with Blazor/C# applications. Developers can now also integrate applications with Angular, React, Vue.js and Co in the MAUI process just like Blazor.

Must use scripts provided by MAUI to interact with the web application

LEAVE A REPLY

Please enter your comment!
Please enter your name here