Skip to content

Commit 22b1d90

Browse files
committed
Set SerializerOptions once up-front
1 parent c9da716 commit 22b1d90

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Http/Routing/src/ValidationEndpointFilterFactory.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static EndpointFilterDelegate Create(EndpointFilterFactoryContext context
2929
return next;
3030
}
3131

32+
var jsonOptions = context.ApplicationServices.GetService<IOptions<JsonOptions>>();
33+
var serializerOptions = jsonOptions?.Value?.SerializerOptions;
34+
options.SerializerOptions = serializerOptions;
35+
3236
var serviceProviderIsService = context.ApplicationServices.GetService<IServiceProviderIsService>();
3337

3438
// Use a list to only store validatable parameters instead of arrays for all parameters
@@ -61,10 +65,6 @@ public static EndpointFilterDelegate Create(EndpointFilterFactoryContext context
6165
{
6266
ValidateContext? validateContext = null;
6367

64-
// Get JsonOptions from DI
65-
var jsonOptions = context.HttpContext.RequestServices.GetService<IOptions<JsonOptions>>();
66-
var serializerOptions = jsonOptions?.Value?.SerializerOptions;
67-
6868
foreach (var entry in validatableParameters)
6969
{
7070
if (entry.Index >= context.Arguments.Count)
@@ -82,7 +82,6 @@ public static EndpointFilterDelegate Create(EndpointFilterFactoryContext context
8282

8383
if (validateContext == null)
8484
{
85-
options.SerializerOptions = serializerOptions;
8685
validateContext = new ValidateContext
8786
{
8887
ValidationOptions = options,

0 commit comments

Comments
 (0)