-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSystemTextJsonStreamerMvcCoreBuilderExtensions.cs
67 lines (59 loc) · 2.45 KB
/
SystemTextJsonStreamerMvcCoreBuilderExtensions.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//////////////////////////////////////////////////////////////////////////////
//
// JsonStreamer - JSON Lines streaming serializer on ASP.NET Core.
// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud)
//
// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0
//
//////////////////////////////////////////////////////////////////////////////
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using JsonStreamer.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using System;
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Extension methods for adding System.Text.Json to <see cref="MvcCoreBuilder"/>.
/// </summary>
public static class SystemTextJsonStreamerMvcCoreBuilderExtensions
{
/// <summary>
/// Configures System.Text.Json specific features with streaming such as input and output formatters.
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddJsonStreamer(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, SystemTextJsonStreamerMvcOptionsSetup>());
return builder;
}
/// <summary>
/// Configures System.Text.Json specific features with streaming such as input and output formatters.
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
/// <param name="setupAction">Callback to configure <see cref="JsonOptions"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddJsonStreamer(
this IMvcCoreBuilder builder,
Action<JsonOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, SystemTextJsonStreamerMvcOptionsSetup>());
return builder;
}
}