Utils.DotNetCore.ServiceCollection 1.0.1

dotnet add package Utils.DotNetCore.ServiceCollection --version 1.0.1
                    
NuGet\Install-Package Utils.DotNetCore.ServiceCollection -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Utils.DotNetCore.ServiceCollection" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Utils.DotNetCore.ServiceCollection" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Utils.DotNetCore.ServiceCollection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Utils.DotNetCore.ServiceCollection --version 1.0.1
                    
#r "nuget: Utils.DotNetCore.ServiceCollection, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Utils.DotNetCore.ServiceCollection@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Utils.DotNetCore.ServiceCollection&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Utils.DotNetCore.ServiceCollection&version=1.0.1
                    
Install as a Cake Tool

Utils.DotNetCore.ServiceCollection - Get Config Value extension

A small utility library that extends Microsoft.Extensions.Configuration with strongly-typed helpers for retrieving configuration values in a safe and expressive way.

Features

  • Strongly-typed configuration access – Retrieve values directly as int, bool, string, custom POCOs, etc.
  • Nested key lookup – Pass multiple keys (params string[]) to walk through hierarchical configuration sections.
  • Fail-fast or fallback options:
    • GetConfigurationValue<T> – throws if the key does not exist or cannot be bound.
    • GetConfigurationValueOrDefault<T> – returns a default value if the key is missing or null.

Installation

Add a reference to your project:

dotnet add package Utils.DotNetCore.ServiceCollection

Config file example

{
  "ConnectionStrings": {
    "Default": "Server=myserver;Database=mydb;User Id=sa;Password=secret;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning"
    }
  },
  "FeatureFlags": {
    "EnableNewUI": true
  }
}

Basic usage

namespace Sample.Use.Console
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            builder.Configuration.AddJsonFile("config.json", optional: false, reloadOnChange: true);

            IConfiguration configuration = builder.Configuration;

            var connectionString = configuration.GetConfigurationValue<string>("ConnectionStrings", "Default");
            System.Console.WriteLine(string.Concat("ConnectionStrings", ":", "Default", "=", connectionString));

            var enableNewUI = configuration.GetConfigurationValue<bool>("FeatureFlags", "EnableNewUI");
            System.Console.WriteLine(string.Concat("FeatureFlags", ":", "EnableNewUI", "=", enableNewUI));

            var maxRetries = configuration.GetConfigurationValueOrDefault(3, "AppSettings", "MaxRetries");
            System.Console.WriteLine(string.Concat("AppSettings", ":", "MaxRetries", "=", maxRetries));

            var loggingOptions = configuration.GetConfigurationValue<LoggingOptions>("Logging");
            System.Console.WriteLine(string.Concat("Logging", "=", loggingOptions.LogLevel["Default"]));

            System.Console.ReadLine();
        }
    }

    internal class LoggingOptions
    {
        public Dictionary<string, string> LogLevel { get; set; } = new();
    }
}

Nested section access

{
  "AppSettings": {
    "Logging": {
      "Enabled": true,
      "Level": "Debug"
    }
  }
}
bool loggingEnabled = config.GetConfigurationValue<bool>("AppSettings", "Logging", "Enabled");
string logLevel = config.GetConfigurationValue<string>("AppSettings", "Logging", "Level");

Using defaults for missed keys

int timeout = config.GetConfigurationValueOrDefault(30, "AppSettings", "Timeout");

Binding to complex types

public class LoggingOptions
{
    public bool Enabled { get; set; }
    public string Level { get; set; }
}

LoggingOptions options = config.GetConfigurationValue<LoggingOptions>("AppSettings", "Logging");

Comparison

Feature IConfiguration.GetValue<T> (built-in) GetConfigurationValue<T> (this library) GetConfigurationValueOrDefault<T> (this library)
Supports nested hierarchical keys ❌ Only colon-delimited string keys ✅ Accepts multiple keys via params array ✅ Accepts multiple keys via params array
Throws if key does not exist ❌ Returns default(T) silently ✅ Throws KeyNotFoundException ❌ Returns provided default value
Throws if binding fails ❌ Returns default(T) silently ✅ Throws InvalidOperationException ❌ Returns provided default value
Provides safe defaults ✅ Requires specifying default(T) inline ❌ Always throws on missing/bad values ✅ Returns provided fallback value
Works with complex POCOs ❌ Only scalar values ✅ Supports binding to objects ✅ Supports binding to objects
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 189 10/17/2025