EnvironmentVariables 0.1.0
See the version list below for details.
dotnet add package EnvironmentVariables --version 0.1.0
NuGet\Install-Package EnvironmentVariables -Version 0.1.0
<PackageReference Include="EnvironmentVariables" Version="0.1.0" />
paket add EnvironmentVariables --version 0.1.0
#r "nuget: EnvironmentVariables, 0.1.0"
// Install EnvironmentVariables as a Cake Addin #addin nuget:?package=EnvironmentVariables&version=0.1.0 // Install EnvironmentVariables as a Cake Tool #tool nuget:?package=EnvironmentVariables&version=0.1.0
EnvironmentVariables
Small .NET Standard library to easy access to all environment variables you need. Targets .NET Standard 2.1 (.NET Core 3.x)
Installation
Install with NuGet Package Manager Console
Install-Package EnvironmentVariables
Install with .NET CLI
dotnet add package EnvironmentVariables
Usage
Step 1: Create class that describes all variables you need to access (POCO)
Use public properties, not fields. Add Env
attribute with variable name to every property you want to get from environment.
using EnvironmentVariables;
public class EnvConfig
{
[Env("ASPNETCORE_ENVIRONMENT")]
public string AspNetCoreEnvironment { get; set; }
[Env("MY_ENV_INT")]
public int MyEnvInt { get; set; }
[Env("MY_ENV_BOOL")]
public bool MyEnvBool { get; set; }
[Env("MY_ENV_STRING_ARRAY")]
public string[] MyEnvStringArray { get; set; }
[Env("MY_ENV_INT_DICT")]
public Dictionary<int, string> MyEnvIntStrDictionary { get; set; }
}
Step 2: Create provider to access your variables
Create new EnvironmentProvider
with class your crated earlier as a type parameter.
using EnvironmentVariables;
var provider = new EnvironmentProvider<EnvConfig>();
Access variables with Values
property
Console.WriteLine(provider.Values.AspNetCoreEnvironment);
//Development
Console.WriteLine(provider.Values.MyEnvInt);
//123
Console.WriteLine(provider.Values.MyEnvBool);
//True
Type support
This library supports:
string
- all built-in value types (
bool
,int
,long
,float
,double
,decimal
, etc.) - collections (
IEnumerable
,Array
,List
, etc.) Dictionary
Enum
Nullable<>
You can check Tests
project to make sure that particular type is supported.
Collections
For collections in your environment variables use ,
or ;
as delimiter:
one,two,three
one;two;three
Dictionaries
For dictionaries in your environment variables use =
or :
as delimiter between key and value:
firstkey=123;secondkey=321;thirdkey=0
1:true, 2:false, 3:true
Converter ignores spaces so feel free to use it anywhere you want.
Other features
You may specify the function that will be used to access variables values
var provider = new EnvironmentProvider<EnvConfig>() {
EnvProvider = name => ThisIsMyFunctionToAccessTheValues(name)
};
Use selflog for debugging
var provider = new EnvironmentProvider<EnvConfig>() {
SelfLog = log => Console.WriteLine(log)
};
Use Reload
to reload values from environment
provider.Reload();
License
Product | Versions 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.