-
Notifications
You must be signed in to change notification settings - Fork 740
/
MemoryConfigurationBuilderExtensions.cs
50 lines (45 loc) · 2.1 KB
/
MemoryConfigurationBuilderExtensions.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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration.Memory;
namespace Microsoft.Extensions.Configuration
{
/// <summary>
/// IConfigurationBuilder extension methods for the MemoryConfigurationProvider.
/// </summary>
public static class MemoryConfigurationBuilderExtensions
{
/// <summary>
/// Adds the memory configuration provider to <paramref name="configurationBuilder"/>.
/// </summary>
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddInMemoryCollection(this IConfigurationBuilder configurationBuilder)
{
if (configurationBuilder == null)
{
throw new ArgumentNullException(nameof(configurationBuilder));
}
configurationBuilder.Add(new MemoryConfigurationSource());
return configurationBuilder;
}
/// <summary>
/// Adds the memory configuration provider to <paramref name="configurationBuilder"/>.
/// </summary>
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="initialData">The data to add to memory configuration provider.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddInMemoryCollection(
this IConfigurationBuilder configurationBuilder,
IEnumerable<KeyValuePair<string, string>> initialData)
{
if (configurationBuilder == null)
{
throw new ArgumentNullException(nameof(configurationBuilder));
}
configurationBuilder.Add(new MemoryConfigurationSource { InitialData = initialData });
return configurationBuilder;
}
}
}