Skip to content

Commit 2694d90

Browse files
Copilotcaptainsafia
andcommitted
Update ValidationEndpointFilterFactory to use type-safe DI for JsonOptions
Co-authored-by: captainsafia <[email protected]>
1 parent 0900ced commit 2694d90

File tree

4 files changed

+4
-165
lines changed

4 files changed

+4
-165
lines changed

src/Http/Routing/src/ValidationEndpointFilterFactory.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.ComponentModel.DataAnnotations;
77
using System.Linq;
88
using System.Reflection;
9-
using System.Text.Json;
9+
using Microsoft.AspNetCore.Http.Json;
1010
using Microsoft.AspNetCore.Http.Metadata;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Options;
@@ -56,18 +56,9 @@ public static EndpointFilterDelegate Create(EndpointFilterFactoryContext context
5656
{
5757
ValidateContext? validateContext = null;
5858

59-
// JsonOptions will be retrieved from DI to set the SerializerOptions
60-
var jsonOptionsType = Type.GetType("Microsoft.AspNetCore.Http.Json.JsonOptions, Microsoft.AspNetCore.Http.Extensions");
61-
JsonSerializerOptions? serializerOptions = null;
62-
if (jsonOptionsType is not null)
63-
{
64-
var jsonOptions = context.HttpContext.RequestServices.GetService(jsonOptionsType);
65-
if (jsonOptions is not null)
66-
{
67-
var serializerOptionsProperty = jsonOptionsType.GetProperty("SerializerOptions");
68-
serializerOptions = serializerOptionsProperty?.GetValue(jsonOptions) as JsonSerializerOptions;
69-
}
70-
}
59+
// Get JsonOptions from DI
60+
var jsonOptions = context.HttpContext.RequestServices.GetService<IOptions<JsonOptions>>();
61+
var serializerOptions = jsonOptions?.Value?.SerializerOptions;
7162

7263
for (var i = 0; i < context.Arguments.Count; i++)
7364
{

src/JSInterop/Microsoft.JSInterop.JS/src/package.json.bak

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/SignalR/clients/ts/signalr-protocol-msgpack/package.json.bak

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/SignalR/clients/ts/signalr/package.json.bak

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)