This commit is contained in:
TheXamlGuy
2024-05-27 04:19:07 +01:00
parent cfc79e26f0
commit dd55a67102
3 changed files with 29 additions and 6 deletions
+27 -4
View File
@@ -4,7 +4,9 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Physical; using Microsoft.Extensions.FileProviders.Physical;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System.Collections.ObjectModel;
using System.Text.Json; using System.Text.Json;
using static System.Collections.Specialized.BitVector32;
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
@@ -60,7 +62,6 @@ public static class IHostBuilderExtension
builder.ConfigureServices((context, services) => builder.ConfigureServices((context, services) =>
{ {
HashSet<string> sections = []; HashSet<string> sections = [];
if (section.EndsWith(":*")) if (section.EndsWith(":*"))
{ {
section = section[..^1]; section = section[..^1];
@@ -72,7 +73,7 @@ public static class IHostBuilderExtension
if (segments.Length > 2) if (segments.Length > 2)
{ {
string keyPrefix = string.Join(':', segments.Take(2)); string keyPrefix = string.Join(':', segments.Take(2));
if (!keyPrefix.EndsWith(":*")) if (keyPrefix.StartsWith(section) && !keyPrefix.EndsWith(":*"))
{ {
sections.Add(keyPrefix); sections.Add(keyPrefix);
} }
@@ -82,11 +83,33 @@ public static class IHostBuilderExtension
} }
else else
{ {
sections.Add(section); if (context.Configuration is ConfigurationRoot root)
{
sections.Add(section);
}
} }
foreach (string section in sections) foreach (string section in sections)
{ {
if (context.Properties.TryGetValue(section, out object? value))
{
if (value is List<Type> configurations)
{
if (configurations.Contains(typeof(TConfiguration)))
{
return;
}
else
{
configurations.Add(typeof(TConfiguration));
}
}
}
else
{
context.Properties.Add(section, new List<Type> { typeof(TConfiguration) });
}
services.TryAddSingleton<IConfigurationFile<TConfiguration>>(provider => services.TryAddSingleton<IConfigurationFile<TConfiguration>>(provider =>
{ {
IFileInfo? fileInfo = null; IFileInfo? fileInfo = null;
+1 -1
View File
@@ -2,5 +2,5 @@
public interface IProxyService<TService> public interface IProxyService<TService>
{ {
TService Proxy { get; } TService Value { get; }
} }
+1 -1
View File
@@ -3,5 +3,5 @@
public class ProxyService<TService>(TService proxy) : public class ProxyService<TService>(TService proxy) :
IProxyService<TService> IProxyService<TService>
{ {
public TService Proxy { get; private set; } = proxy; public TService Value { get; private set; } = proxy;
} }