-
Notifications
You must be signed in to change notification settings - Fork 10k
/
NewtonsoftJsonMvcBuilderExtensions.cs
44 lines (37 loc) · 1.62 KB
/
NewtonsoftJsonMvcBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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.Mvc;
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Extensions methods for configuring MVC via an <see cref="IMvcBuilder"/>.
/// </summary>
public static class NewtonsoftJsonMvcBuilderExtensions
{
/// <summary>
/// Configures Newtonsoft.Json specific features such as input and output formatters.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddNewtonsoftJson(this IMvcBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);
NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(builder.Services);
return builder;
}
/// <summary>
/// Configures Newtonsoft.Json specific features such as input and output formatters.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
/// <param name="setupAction">Callback to configure <see cref="MvcNewtonsoftJsonOptions"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddNewtonsoftJson(
this IMvcBuilder builder,
Action<MvcNewtonsoftJsonOptions> setupAction)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(setupAction);
NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(builder.Services);
builder.Services.Configure(setupAction);
return builder;
}
}