NPv.Common.Configuration
1.0.0
See the version list below for details.
dotnet add package NPv.Common.Configuration --version 1.0.0
NuGet\Install-Package NPv.Common.Configuration -Version 1.0.0
<PackageReference Include="NPv.Common.Configuration" Version="1.0.0" />
<PackageVersion Include="NPv.Common.Configuration" Version="1.0.0" />
<PackageReference Include="NPv.Common.Configuration" />
paket add NPv.Common.Configuration --version 1.0.0
#r "nuget: NPv.Common.Configuration, 1.0.0"
#:package NPv.Common.Configuration@1.0.0
#addin nuget:?package=NPv.Common.Configuration&version=1.0.0
#tool nuget:?package=NPv.Common.Configuration&version=1.0.0
NPv.Common.Configuration
NPv.Common.Configuration is a lightweight utility library that provides strict access helpers for working with IConfiguration
from Microsoft.Extensions.Configuration
.
It simplifies reading required configuration values by throwing clear exceptions when a key is missing or invalid.
📦 Installation
Install via NuGet:
dotnet add package NPv.Common.Configuration
Or via the Package Manager Console:
Install-Package NPv.Common.Configuration
✨ Features
GetRequiredValue<T>(key)
Retrieve a strongly-typed configuration value or throw an exception if it's missing:
GetRequiredString(key)
Retrieve a non-empty string value or throw an exception:
GetConnectionString()
Retrieve the "Default" connection string or throw an exception if not found:
All methods use InvalidOperationException
to clearly indicate misconfiguration at runtime.
🚀 Usage Example
using Microsoft.Extensions.Configuration;
using NPv.Common.Configuration;
public class MyService
{
public MyService(IConfiguration configuration)
{
var apiKey = configuration.GetRequiredString("MyService:ApiKey");
var retryCount = configuration.GetRequiredValue<int>("MyService:MaxRetries");
var defaultConnection = configuration.GetConnectionString();
}
}
Example appsettings.json:
{
"MyService": {
"ApiKey": "abc123",
"MaxRetries": 5
},
"ConnectionStrings": {
"Default": "Server=localhost;Database=app;Trusted_Connection=True;"
}
}
🔐 License
This project is licensed under the MIT License. See the LICENSE.txt file for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.2)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.