Skip to content

Commit 7e6674c

Browse files
authored
Add ConfigureRouteHandlerJsonOptions for M.A.Htt.Json.JsonOptions (#39502)
* Add ConfigureHttpJsonOptions for M.A.Htt.Json.JsonOptions * Address initial feedback from API review * Fix method reference in doc comment * Fix up crefs
1 parent 85ac505 commit 7e6674c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.AspNetCore.Http.Json;
5+
6+
namespace Microsoft.Extensions.DependencyInjection;
7+
8+
/// <summary>
9+
/// Extension methods to configure JSON serialization behavior.
10+
/// </summary>
11+
public static class RouteHandlerJsonServiceExtensions
12+
{
13+
/// <summary>
14+
/// Configures options used for reading and writing JSON by route handlers.
15+
/// </summary>
16+
/// <remarks>
17+
/// The options configured here will only affect JSON returned and processed
18+
/// from route handlers, not controllers, when using <see cref="O:Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync" />
19+
/// and <see cref="O:Microsoft.AspNetCore.Http.HttpResponseJsonExtensions.WriteAsJsonAsync" />.
20+
/// </remarks>
21+
/// <param name="services">The <see cref="IServiceCollection" /> to configure options on.</param>
22+
/// <param name="configureOptions">The <see cref="Action{JsonOptions}"/> to configure the
23+
/// <see cref="JsonOptions"/>.</param>
24+
/// <returns>The modified <see cref="IServiceCollection"/>.</returns>
25+
public static IServiceCollection ConfigureRouteHandlerJsonOptions(this IServiceCollection services, Action<JsonOptions> configureOptions)
26+
{
27+
services.Configure<JsonOptions>(configureOptions);
28+
return services;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#nullable enable
2+
Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions
3+
static Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions.ConfigureRouteHandlerJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<Microsoft.AspNetCore.Http.Json.JsonOptions!>! configureOptions) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!

0 commit comments

Comments
 (0)