Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConfigureRouteHandlerJsonOptions for M.A.Htt.Json.JsonOptions #39502

Merged
merged 4 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Http;
captainsafia marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Extension methods to configure JSON serialization behavior.
/// </summary>
public static class HttpJsonServiceExtensions
{
/// <summary>
/// Configures options used for reading and writing JSON by route handlers.
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// The options configured here will only affect JSON returned and processed
/// from route handlers, not controllers.
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
/// </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 ConfigureHttpJsonOptions(this IServiceCollection services, Action<JsonOptions> configureOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should review this name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the first time we're adding a ConfigureWhatever() IServiceCollection extension method for an option type? I guess in most cases it wouldn't be necessary because you could have an overload that takes a configureOptions callback to AddWhatever() for most option types.

The only thing I see right now that's close to this is ConfigureApplicationCookie() and ConfigureExternalCookie() which use named options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the name to ConfigureRouteHandlerJsonOptions per our email conversation but open to other ideas.

{
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.AspNetCore.Http.HttpJsonServiceExtensions
static Microsoft.AspNetCore.Http.HttpJsonServiceExtensions.ConfigureHttpJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<Microsoft.AspNetCore.Http.Json.JsonOptions!>! configureOptions) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!