More work in this Configuration Manager
This commit is contained in:
parent
8e6492e979
commit
21d7128e74
11 changed files with 299 additions and 79 deletions
|
|
@ -18,7 +18,7 @@ namespace Core.Configurations
|
|||
{
|
||||
if (_configurationBuilder == null)
|
||||
{
|
||||
var envConfiguration = new ConfigurationBuilder()
|
||||
var envConfiguration = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ namespace Core.Configurations
|
|||
var appConfigEndpoint = envConfiguration["AppConfigEndpoint"];
|
||||
var appConfigLabel = envConfiguration["AppConfigLabelFilter"];
|
||||
|
||||
_configurationBuilder = new ConfigurationBuilder();
|
||||
_configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();
|
||||
if (!string.IsNullOrEmpty(appConfigEndpoint))
|
||||
{
|
||||
_configurationBuilder
|
||||
|
|
|
|||
61
Core/Configurations/ConfigurationBuilder.cs
Normal file
61
Core/Configurations/ConfigurationBuilder.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Configurations
|
||||
{
|
||||
public class ConfigurationBuilder
|
||||
{
|
||||
private readonly List<IConfigurationProvider> _providers = new();
|
||||
|
||||
public ConfigurationBuilder AddProvider(IConfigurationProvider provider)
|
||||
{
|
||||
_providers.Add(provider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IConfigurationRoot Build()
|
||||
{
|
||||
// Her kan du implementere din egen sammenlægningslogik
|
||||
return new ConfigurationRoot(_providers);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigurationRoot : IConfigurationRoot
|
||||
{
|
||||
public ConfigurationRoot(List<IConfigurationProvider> configurationProviders)
|
||||
{
|
||||
|
||||
}
|
||||
public T GetSection<T>(string key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public static class ConfigurationPredicateExtensions
|
||||
{
|
||||
|
||||
public static IConfigurationSection GetSection(this IConfigurationRoot configurationSection, string key)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static T Get<T>(this IConfigurationSection configuration, string key)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
public interface IConfigurationProvider
|
||||
{
|
||||
Dictionary<string, object> Configuration();
|
||||
}
|
||||
|
||||
public interface IConfigurationSection
|
||||
{
|
||||
string Key { get; }
|
||||
string Path { get; }
|
||||
string Value { get; set; }
|
||||
}
|
||||
}
|
||||
14
Core/Configurations/IConfigurationRoot.cs
Normal file
14
Core/Configurations/IConfigurationRoot.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Configurations
|
||||
{
|
||||
public interface IConfigurationRoot
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Core.Configurations.PostgresqlConfigurationBuilder
|
||||
{
|
||||
public class PostgresConfigurationSource : IConfigurationSource
|
||||
public class PostgresConfigurationSource : Microsoft.Extensions.Configuration.IConfigurationSource
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
private readonly string _channel;
|
||||
|
|
@ -21,7 +21,7 @@ namespace Core.Configurations.PostgresqlConfigurationBuilder
|
|||
_configurationQuery = configurationQuery ?? throw new ArgumentNullException(nameof(configurationQuery));
|
||||
}
|
||||
|
||||
public IConfigurationProvider Build(IConfigurationBuilder builder)
|
||||
public Microsoft.Extensions.Configuration.IConfigurationProvider Build(IConfigurationBuilder builder)
|
||||
{
|
||||
return new PostgresConfigurationProvider(_connectionString, _channel, _configurationQuery);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using Microsoft.Extensions.Primitives;
|
|||
using System.Data;
|
||||
|
||||
namespace Core.Configurations.SmartConfiguration;
|
||||
public class JsonConfiguration : IConfiguration
|
||||
public class JsonConfiguration : Microsoft.Extensions.Configuration.IConfiguration
|
||||
{
|
||||
private readonly JObject _data;
|
||||
|
||||
|
|
@ -19,11 +19,16 @@ public class JsonConfiguration : IConfiguration
|
|||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IConfigurationSection GetSection(string key) =>
|
||||
new JsonConfigurationSection(_data, key);
|
||||
public Microsoft.Extensions.Configuration.IConfigurationSection GetSection(string key) => null;
|
||||
//new JsonConfigurationSection(_data, key);
|
||||
|
||||
public IEnumerable<IConfigurationSection> GetChildren() =>
|
||||
_data.Properties().Select(p => new JsonConfigurationSection(_data, p.Name));
|
||||
|
||||
public IChangeToken GetReloadToken() => throw new NotImplementedException();
|
||||
|
||||
IEnumerable<Microsoft.Extensions.Configuration.IConfigurationSection> IConfiguration.GetChildren()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -43,12 +43,12 @@ namespace Core.Configurations.SmartConfiguration
|
|||
set => throw new NotImplementedException("Setting values is not supported.");
|
||||
}
|
||||
|
||||
public IConfigurationSection GetSection(string key)
|
||||
public Microsoft.Extensions.Configuration.IConfigurationSection GetSection(string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
|
||||
return new JsonConfigurationSection(_data, string.IsNullOrEmpty(_path) ? key : $"{_path}:{key}");
|
||||
return null;// new JsonConfigurationSection(_data, string.IsNullOrEmpty(_path) ? key : $"{_path}:{key}");
|
||||
}
|
||||
|
||||
public JToken GetToken() => _data.SelectToken(_normalizedPath);
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ namespace Core.Configurations
|
|||
{
|
||||
if (_configurationBuilder == null)
|
||||
{
|
||||
var envConfiguration = new ConfigurationBuilder()
|
||||
var envConfiguration = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var appConfigEndpoint = envConfiguration["AppConfigEndpoint"];
|
||||
var appConfigLabel = envConfiguration["AppConfigLabelFilter"];
|
||||
|
||||
_configurationBuilder = new ConfigurationBuilder();
|
||||
_configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();
|
||||
if (!string.IsNullOrEmpty(appConfigEndpoint))
|
||||
{
|
||||
_configurationBuilder
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue