diff --git a/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md index 539ebef42c..243447c359 100644 --- a/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md +++ b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md @@ -1,14 +1,16 @@ -# ASP.NET Core SignalR New Features (Summary) +### ASP.NET Core SignalR New Features — Summary -In this article, I'll highlight .**NET 9's SignalR updates** for ASP.NET Core 9.0. +In this article, I’ll highlight the latest .**NET 9 SignalR updates** for ASP.NET Core 9.0. -![cover](cover.png) +![Cover](cover.png) -## Hub Accept a Base Class -In this version, your `Hub` class can now get a base class of a polymorphic class. As you see in the below example; I can send `Animal` to my Hub method. Before we could only pass the derived class like `Cat` and `Dog`. -```csharp +### SignalR Hub Accepts Base Classes + +SignalR `Hub` class can now get a base class of a polymorphic class. As you see in the example below, I can send `Animal` to `Process` method. Before .NET 9, we could only pass the derived classes: `Cat` and `Dog`. + +``` /*** My Base Class is Animal ***/ [JsonPolymorphic] [JsonDerivedType(typeof(Cat), nameof(Cat))] @@ -45,13 +47,13 @@ public class MyHub : Hub -## Better Diagnostics and Telemetry +### Better Diagnostics and Telemetry -SignalR now integrates more deeply with the .NET Activity API, which is commonly used for distributed tracing. This enhancement is mostly implemented for better monitoring in [.NET Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview?tabs=bash#using-the-dashboard-with-net-aspire-projects). To support the improved telemetry feature: +Microsoft focuses mainly on .NET Aspire nowadays. That’s why SignalR now integrates more deeply with the .NET Activity API, which is commonly used for distributed tracing. The enhancement is implemented for better monitoring in [.NET Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview?tabs=bash#using-the-dashboard-with-net-aspire-projects). To support this feature: 1- Add these packages to your`csproj`: -```xml +``` @@ -59,7 +61,7 @@ SignalR now integrates more deeply with the .NET Activity API, which is commonly 2- Add the following startup code to your host project: -```csharp +``` builder.Services.AddSignalR(); /* After AddSignalR use AddOpenTelemetry() */ builder @@ -79,15 +81,19 @@ builder builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); ``` -And you'll see the SignalR Hub calls at the Aspire Dashboard: +Finally, you’ll see the **SignalR Hub** events on the [Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview): + +![.NET Aspire Activity Dashboard](signalr-activity-dashboard.png) -![image-20241002183315780](C:\Users\alper\AppData\Roaming\Typora\typora-user-images\image-20241002183315780.png) +### Trimming and Native AOT Support -## Trimming and Native AOT Support +With .NET 9, **trimming** and **native** **Ahead Of Time** compilation are **supported**. This will improve our application performance. To support AOT, your SignalR object serialization needs to be JSON, and you must use the `System.Text.Json` s[ource generator](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation). Also on the server side, [you shouldn't use](https://github.com/dotnet/aspnetcore/issues/56179) `IAsyncEnumerable` and `ChannelReader` where `T` is a ValueType (`struct`) for Hub method arguments. One more limitation; [Strongly typed hubs](https://learn.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-8.0#strongly-typed-hubs) aren't supported with Native AOT (`PublishAot`). And you should use only `Task`, `Task`, `ValueTask`, `ValueTask` for `async` return types. -In this version, **trimming** and native **Ahead Of Time** compilation are **supported**. It'll improve your app's performance. To support AOT, your serialization object needs to be JSON and you must use the `System.Text.Json` Source Generator. Also on the server side, [you shouldn't use](https://github.com/dotnet/aspnetcore/issues/56179) `IAsyncEnumerable` and `ChannelReader` where `T` is a ValueType (`struct`) for Hub method arguments. Besides, [Strongly typed hubs](https://learn.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-8.0#strongly-typed-hubs) aren't supported with Native AOT (`PublishAot`). And you should use only `Task`, `Task`, `ValueTask`, `ValueTask` for `async` return types. +--- +That's all the new features coming to SignalR in .NET 9! +Happy coding 🧑🏽‍💻 diff --git a/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/signalr-activity-dashboard.png b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/signalr-activity-dashboard.png new file mode 100644 index 0000000000..44f167c603 Binary files /dev/null and b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/signalr-activity-dashboard.png differ