-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathMemoryFileProviderConfigurationBuilderExtensions.cs
More file actions
77 lines (64 loc) · 2.81 KB
/
Copy pathMemoryFileProviderConfigurationBuilderExtensions.cs
File metadata and controls
77 lines (64 loc) · 2.81 KB
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
68
69
70
71
72
73
74
75
76
77
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Ini;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.Configuration.Xml;
namespace Steeltoe.Common.TestResources;
public static class MemoryFileProviderConfigurationBuilderExtensions
{
internal const string AppSettingsJsonFileName = "appsettings.json";
internal const string AppSettingsXmlFileName = "appsettings.xml";
internal const string AppSettingsIniFileName = "appsettings.ini";
public static void AddInMemoryAppSettingsJsonFile(this IConfigurationBuilder builder, MemoryFileProvider fileProvider)
{
AddInMemoryJsonFile(builder, fileProvider, AppSettingsJsonFileName);
}
public static void AddInMemoryJsonFile(this IConfigurationBuilder builder, MemoryFileProvider fileProvider, string path)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(fileProvider);
ArgumentException.ThrowIfNullOrEmpty(path);
var source = new JsonConfigurationSource
{
FileProvider = fileProvider,
Path = path,
Optional = false,
ReloadOnChange = true,
// Turn off debounce, so the change token triggers immediately. Then we don't need to sleep in tests.
ReloadDelay = 0
};
builder.Add(source);
}
public static void AddInMemoryAppSettingsXmlFile(this IConfigurationBuilder builder, MemoryFileProvider fileProvider)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(fileProvider);
var source = new XmlConfigurationSource
{
FileProvider = fileProvider,
Path = AppSettingsXmlFileName,
Optional = false,
ReloadOnChange = true,
// Turn off debounce, so the change token triggers immediately. Then we don't need to sleep in tests.
ReloadDelay = 0
};
builder.Add(source);
}
public static void AddInMemoryAppSettingsIniFile(this IConfigurationBuilder builder, MemoryFileProvider fileProvider)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(fileProvider);
var source = new IniConfigurationSource
{
FileProvider = fileProvider,
Path = AppSettingsIniFileName,
Optional = false,
ReloadOnChange = true,
// Turn off debounce, so the change token triggers immediately. Then we don't need to sleep in tests.
ReloadDelay = 0
};
builder.Add(source);
}
}