Expose IConfigurationProviders from root
This commit is contained in:
Родитель
6e410fd8a9
Коммит
427aecc6f8
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.Extensions.Configuration
|
||||
{
|
||||
|
@ -14,5 +15,10 @@ namespace Microsoft.Extensions.Configuration
|
|||
/// Force the configuration values to be reloaded from the underlying <see cref="IConfigurationProvider"/>s.
|
||||
/// </summary>
|
||||
void Reload();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IConfigurationProvider"/>s for this configuration.
|
||||
/// </summary>
|
||||
IEnumerable<IConfigurationProvider> Providers { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[
|
||||
{
|
||||
"TypeId": "public interface Microsoft.Extensions.Configuration.IConfigurationRoot : Microsoft.Extensions.Configuration.IConfiguration",
|
||||
"MemberId": "System.Collections.Generic.IEnumerable<Microsoft.Extensions.Configuration.IConfigurationProvider> get_Providers()",
|
||||
"Kind": "Addition"
|
||||
}
|
||||
]
|
|
@ -36,6 +36,11 @@ namespace Microsoft.Extensions.Configuration
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IConfigurationProvider"/>s for this configuration.
|
||||
/// </summary>
|
||||
public IEnumerable<IConfigurationProvider> Providers => _providers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value corresponding to a configuration key.
|
||||
/// </summary>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
|
@ -859,6 +860,23 @@ IniKey1=IniValue2");
|
|||
File.Delete(xmlConfigFilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanEnumerateProviders()
|
||||
{
|
||||
// Arrange
|
||||
var config = CreateBuilder()
|
||||
.AddIniFile(_iniFile, optional: true, reloadOnChange: true)
|
||||
.AddJsonFile(_jsonFile, optional: true, reloadOnChange: true)
|
||||
.AddXmlFile(_xmlFile, optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
var providers = config.Providers;
|
||||
Assert.Equal(3, providers.Count());
|
||||
Assert.NotNull(providers.Single(p => p is JsonConfigurationProvider));
|
||||
Assert.NotNull(providers.Single(p => p is XmlConfigurationProvider));
|
||||
Assert.NotNull(providers.Single(p => p is IniConfigurationProvider));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_fileProvider.Dispose();
|
||||
|
|
Загрузка…
Ссылка в новой задаче