Skip to content

Commit

Permalink
Add ConfigureRouteHandlerJsonOptions for M.A.Htt.Json.JsonOptions (#3…
Browse files Browse the repository at this point in the history
…9502)

* Add ConfigureHttpJsonOptions for M.A.Htt.Json.JsonOptions

* Address initial feedback from API review

* Fix method reference in doc comment

* Fix up crefs
  • Loading branch information
captainsafia authored Jan 21, 2022
1 parent 85ac505 commit 7e6674c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Http/Http.Extensions/src/HttpJsonServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Http.Json;

namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Extension methods to configure JSON serialization behavior.
/// </summary>
public static class RouteHandlerJsonServiceExtensions
{
/// <summary>
/// Configures options used for reading and writing JSON by route handlers.
/// </summary>
/// <remarks>
/// The options configured here will only affect JSON returned and processed
/// from route handlers, not controllers, when using <see cref="O:Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync" />
/// and <see cref="O:Microsoft.AspNetCore.Http.HttpResponseJsonExtensions.WriteAsJsonAsync" />.
/// </remarks>
/// <param name="services">The <see cref="IServiceCollection" /> to configure options on.</param>
/// <param name="configureOptions">The <see cref="Action{JsonOptions}"/> to configure the
/// <see cref="JsonOptions"/>.</param>
/// <returns>The modified <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection ConfigureRouteHandlerJsonOptions(this IServiceCollection services, Action<JsonOptions> configureOptions)
{
services.Configure<JsonOptions>(configureOptions);
return services;
}
}
2 changes: 2 additions & 0 deletions src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions
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 comments on commit 7e6674c

Please sign in to comment.