CS.EnvConfig
0.0.3
dotnet add package CS.EnvConfig --version 0.0.3
NuGet\Install-Package CS.EnvConfig -Version 0.0.3
<PackageReference Include="CS.EnvConfig" Version="0.0.3" />
<PackageVersion Include="CS.EnvConfig" Version="0.0.3" />
<PackageReference Include="CS.EnvConfig" />
paket add CS.EnvConfig --version 0.0.3
#r "nuget: CS.EnvConfig, 0.0.3"
#:package CS.EnvConfig@0.0.3
#addin nuget:?package=CS.EnvConfig&version=0.0.3
#tool nuget:?package=CS.EnvConfig&version=0.0.3
EnvConfig
EnvConfig is a lightweight library that simplifies retrieving configuration values from environment variables. It uses attributes to map environment variables onto class properties, offering convenient defaults for each property type.
Installation
# Install the latest version from NuGet
dotnet add package CS.EnvConfig
# Install the specific version
dotnet add package CS.EnvConfig --version 0.0.2
Usage
- Create a configuration class with properties annotated using
[EnvVar]. - Use
EnvConfigLoader.Load<YourConfig>()to populate those properties from environment variables if available; otherwise default values are used.
Example:
public class MyConfig
{
[EnvVar("API_ENDPOINT", "https://default.api")]
public string? API_ENDPOINT { get; set; }
[EnvVar("RETRY_COUNT", 3)]
public int? RETRY_COUNT { get; set; }
[EnvVar("MY_BOOL", true)]
public bool? MY_BOOL { get; set; }
[EnvVar("MY_BOOL_2", false)]
public bool? MY_BOOL_2 { get; set; }
[EnvVar("MY_DOUBLE", 0.123)]
public double? MY_DOUBLE { get; set; }
}
public class Program
{
public static void Main()
{
var config = EnvConfigLoader.Load<MyConfig>();
Console.WriteLine($"API_ENDPOINT: {config.API_ENDPOINT}");
Console.WriteLine($"RETRY_COUNT: {config.RETRY_COUNT}");
}
}
See the example app for a complete example of how to use the library, or the test cases in the EnvConfig/EnvConfig_test.cs.
TODO
- Create a pipeline to publish new version to public NuGet.
Contributing
Feel free to open pull requests or issues to improve the library. You’re welcome to suggest enhancements, report bugs, or contribute documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
- coverlet.collector (>= 6.0.0)
- Microsoft.NET.Test.Sdk (>= 17.8.0)
- NUnit (>= 3.14.0)
- NUnit.Analyzers (>= 3.9.0)
- NUnit3TestAdapter (>= 4.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.