feat(ConfigurationExtension): Hinzufügen der Klasse ConfigurationExtension mit der Methode GetOrDefault zum sichereren Abrufen von Konfigurationen

- Einführung einer neuen statischen Klasse ConfigurationExtension im Namespace DigitalData.Core.Abstractions.
- Hinzufügen der GetOrDefault-Erweiterungsmethode zu IConfiguration, die eine einfachere Abfrage von Konfigurationswerten mit Standardverhalten ermöglicht, wenn diese nicht gefunden werden.
- Aktualisierung der Versionsnummern auf 3.5.0 in den Projektdateien.
This commit is contained in:
Developer 02 2025-04-28 15:44:01 +02:00
parent 653665bb25
commit c81ff2c628
2 changed files with 33 additions and 3 deletions

View File

@ -0,0 +1,30 @@
using Microsoft.Extensions.Configuration;
namespace DigitalData.Core.Abstractions
{
/// <summary>
/// Extension methods for the <see cref="IConfiguration"/> interface, providing
/// additional functionality for retrieving configuration values with default behavior.
/// </summary>
public static class ConfigurationExtension
{
/// <summary>
/// Retrieves a configuration value for the specified key, or returns a default value
/// of type <typeparamref name="T"/> if the configuration is not found or the key is null.
/// </summary>
/// <typeparam name="T">The type of the object to retrieve from the configuration.</typeparam>
/// <param name="configuration">The <see cref="IConfiguration"/> instance.</param>
/// <param name="key">The optional key to look for in the configuration. If null, the method
/// retrieves the root configuration.</param>
/// <returns>
/// An instance of <typeparamref name="T"/> populated from the configuration values, or
/// a new instance of <typeparamref name="T"/> if no matching configuration is found.
/// </returns>
public static T GetOrDefault<T>(this IConfiguration configuration, string? key = null)
where T : new()
=> (key is null
? configuration.Get<T>()
: configuration.GetSection(key).Get<T>())
?? new T();
}
}

View File

@ -17,9 +17,9 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<PackAsTool>False</PackAsTool>
<PackageIcon>core_icon.png</PackageIcon>
<Version>3.4.4</Version>
<AssemblyVersion>3.4.4</AssemblyVersion>
<FileVersion>3.4.4</FileVersion>
<Version>3.5.0</Version>
<AssemblyVersion>3.5.0</AssemblyVersion>
<FileVersion>3.5.0</FileVersion>
</PropertyGroup>
<ItemGroup>