Auto stash before merge of "main" and "origin/main"
This commit is contained in:
parent
cb6dd39596
commit
1f675498a2
10 changed files with 148 additions and 30 deletions
|
|
@ -29,19 +29,52 @@ namespace Core.Configurations
|
|||
}
|
||||
}
|
||||
|
||||
public class ConfigurationRoot : IConfigurationRoot
|
||||
public class Configuration : IConfiguration
|
||||
{
|
||||
List<IConfigurationProvider> IConfigurationRoot.ConfigurationProviders { get; set; }
|
||||
List<IConfigurationProvider> _providers = [];
|
||||
|
||||
public string this[string key]
|
||||
{
|
||||
get => GetConfiguration(_providers, key);
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
List<IConfigurationProvider> IConfiguration.ConfigurationProviders
|
||||
{
|
||||
get { return _providers; }
|
||||
set { _providers = value; }
|
||||
}
|
||||
|
||||
internal static string GetConfiguration(IList<IConfigurationProvider> providers, string key)
|
||||
{
|
||||
string value = null;
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
var test = provider.Configuration().SelectToken(ConfigurationBinder.NormalizePath(key));
|
||||
|
||||
if (test != null)
|
||||
value = test.ToString();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
public class ConfigurationRoot : Configuration, IConfigurationRoot
|
||||
{
|
||||
List<IConfigurationProvider> IConfiguration.ConfigurationProviders { get; set; }
|
||||
|
||||
public ConfigurationRoot(List<IConfigurationProvider> configurationProviders)
|
||||
{
|
||||
((IConfigurationRoot)this).ConfigurationProviders = configurationProviders;
|
||||
((IConfiguration)this).ConfigurationProviders = configurationProviders;
|
||||
}
|
||||
|
||||
}
|
||||
public static class ConfigurationBinder
|
||||
{
|
||||
private static string NormalizePath(string path)
|
||||
public static string NormalizePath(string path)
|
||||
{
|
||||
return path?.Replace(":", ".", StringComparison.Ordinal) ?? string.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
namespace Core.Configurations
|
||||
{
|
||||
public interface IConfigurationRoot
|
||||
{
|
||||
public interface IConfigurationRoot : IConfiguration { }
|
||||
|
||||
public interface IConfiguration
|
||||
{
|
||||
internal List<IConfigurationProvider> ConfigurationProviders { get; set; }
|
||||
string this[string key] { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ namespace Core.Configurations.SmartConfiguration;
|
|||
public interface IConfigurationRepository
|
||||
{
|
||||
IEnumerable<AppConfiguration> GetActiveConfigurations();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,26 @@ namespace Core.Configurations.SmartConfig
|
|||
{
|
||||
return builder.AddProvider(new SmartConfigProvider(builder, configKey, path));
|
||||
}
|
||||
}
|
||||
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, Action<SmartConfigOptions> setupAction)
|
||||
{
|
||||
var options = new SmartConfigOptions();
|
||||
setupAction(options);
|
||||
|
||||
return builder.AddProvider(new SmartConfigProvider(options.GetRepository()));
|
||||
}
|
||||
}
|
||||
public class SmartConfigOptions
|
||||
{
|
||||
private SmartConfiguration.IConfigurationRepository _repository;
|
||||
|
||||
public SmartConfigOptions UseRepository(SmartConfiguration.IConfigurationRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal SmartConfiguration.IConfigurationRepository GetRepository() => _repository;
|
||||
}
|
||||
public class SmartConfigProvider : IConfigurationProvider
|
||||
{
|
||||
string _configKey;
|
||||
|
|
@ -26,6 +44,8 @@ namespace Core.Configurations.SmartConfig
|
|||
|
||||
public SmartConfigProvider() { }
|
||||
|
||||
public SmartConfigProvider(SmartConfiguration.IConfigurationRepository configurationProvider)
|
||||
{ }
|
||||
public SmartConfigProvider(IConfigurationBuilder builder, string configKey, string configurationFilePath)
|
||||
{
|
||||
_builder = builder;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue