You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Optional: Optimize JSON interactions with .NET 6 JSON CodeGeneration
267
+
268
+
Starting with .NET 6, the System.Text.Json.JsonSerializer supports working with optimized code generated for serializing and deserializing JSON payloads. Code is generated at build time, resulting in a significant performance improvement for the serialization and deserialization of JSON data. This is configured by taking the following steps:
269
+
270
+
1. Create a partial Context class that inherits from `System.Text.Json.Serialization.JsonSerializerContext`
271
+
2. Decorate the class with the `System.Text.Json.JsonSourceGenerationOptions` attribute
272
+
3. Add `JsonSerializable` attributes to the class definition for each type that you would like to have code generated
273
+
274
+
We have already written this context for you and it is located in the `BlazingPizza.Shared.Order.cs" file
You can now optimize the calls to the HttpClient in the `OrdersClient` class by passing an `OrderContext.Default` parameter pointing to the type sought as the second parameter. Updating the methods in the `OrdersClient` class should look like the following:
Update each page where an `HttpClient` is used to manage orders to use the new typed `OrdersClient`. Inject an `OrdersClient` instead of an `HttpClient` and use the new client to make the API call. Wrap each call in a `try-catch` that handles exceptions of type `AccessTokenNotAvailableException` by calling the provided `Redirect()` method.
0 commit comments