Update migration for SignalR (#12305)
* Update migration for SignalR * update * Apply suggestions from code review Co-Authored-By: BrennanConroy <brecon@microsoft.com> * Apply suggestions from code review Co-Authored-By: BrennanConroy <brecon@microsoft.com> * sub header * Update aspnetcore/migration/22-to-30.md Co-Authored-By: BrennanConroy <brecon@microsoft.com> * Update 22-to-30.md * update the ms.date metadata value * SignalR migration patch (#12352)pull/12353/head
parent
ae3d90570d
commit
b31aad8d98
|
@ -4,7 +4,7 @@ author: tdykstra
|
|||
description: Learn how to migrate an ASP.NET Core 2.2 project to ASP.NET Core 3.0.
|
||||
ms.author: tdykstra
|
||||
ms.custom: mvc
|
||||
ms.date: 04/17/2019
|
||||
ms.date: 05/09/2019
|
||||
uid: migration/22-to-30
|
||||
---
|
||||
# Migrate from ASP.NET Core 2.2 to 3.0
|
||||
|
@ -437,35 +437,52 @@ The most significant change from `WebHostBuilder` to `HostBuilder` is in [depend
|
|||
|
||||
## Update SignalR code
|
||||
|
||||
If you call `AddJsonProtocol`, replace it with `AddNewtonsoftJsonProtocol`.
|
||||
`System.Text.Json` is now the default Hub Protocol used by both the client and server.
|
||||
|
||||
* The following examples show server code before and after the change:
|
||||
In `Startup.ConfigureServices`, call `AddJsonProtocol` to set serializer options.
|
||||
|
||||
```csharp
|
||||
services.AddSignalR(...)
|
||||
.AddJsonProtocol(...) // 2.2
|
||||
```
|
||||
**Server:**
|
||||
|
||||
```csharp
|
||||
services.AddSignalR(...)
|
||||
.AddNewtonsoftJsonProtocol(...) // 3.0
|
||||
```
|
||||
```csharp
|
||||
services.AddSignalR(...)
|
||||
.AddJsonProtocol(options =>
|
||||
{
|
||||
options.WriteIndented = false;
|
||||
})
|
||||
```
|
||||
|
||||
* The following examples show .NET client code before and after the change:
|
||||
**Client:**
|
||||
|
||||
```csharp
|
||||
connection = new HubConnectionBuilder()
|
||||
.WithUrl(...)
|
||||
.AddJsonProtocol(...) // 2.2
|
||||
.Build()
|
||||
```
|
||||
```csharp
|
||||
new HubConnectionBuilder()
|
||||
.WithUrl("/chatHub")
|
||||
.AddJsonProtocol(options =>
|
||||
{
|
||||
options.WriteIndented = false;
|
||||
})
|
||||
.Build();
|
||||
```
|
||||
|
||||
```csharp
|
||||
connection = new HubConnectionBuilder()
|
||||
.WithUrl(...)
|
||||
.AddNewtonsoftJsonProtocol(...) // 3.0
|
||||
.Build()
|
||||
```
|
||||
### Switch to Newtonsoft.Json
|
||||
|
||||
If you're using features of `Newtonsoft.Json` that aren't supported in `System.Text.Json`, you can switch back to `Newtonsoft.Json`:
|
||||
|
||||
1. Install the [Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson) NuGet package.
|
||||
1. On the client, chain an `AddNewtonsoftJsonProtocol` method call to the `HubConnectionBuilder` instance:
|
||||
|
||||
```csharp
|
||||
new HubConnectionBuilder()
|
||||
.WithUrl("/chatHub")
|
||||
.AddNewtonsoftJsonProtocol(...)
|
||||
.Build();
|
||||
```
|
||||
|
||||
1. On the server, chain an `AddNewtonsoftJsonProtocol` method call to the `AddSignalR` method call in `Startup.ConfigureServices`:
|
||||
|
||||
```csharp
|
||||
services.AddSignalR()
|
||||
.AddNewtonsoftJsonProtocol(...);
|
||||
```
|
||||
|
||||
## Opt in to runtime compilation
|
||||
|
||||
|
|
Loading…
Reference in New Issue