Utils.EnvironmentManager
2.0.0
See the version list below for details.
dotnet add package Utils.EnvironmentManager --version 2.0.0
NuGet\Install-Package Utils.EnvironmentManager -Version 2.0.0
<PackageReference Include="Utils.EnvironmentManager" Version="2.0.0" />
<PackageVersion Include="Utils.EnvironmentManager" Version="2.0.0" />
<PackageReference Include="Utils.EnvironmentManager" />
paket add Utils.EnvironmentManager --version 2.0.0
#r "nuget: Utils.EnvironmentManager, 2.0.0"
#:package Utils.EnvironmentManager@2.0.0
#addin nuget:?package=Utils.EnvironmentManager&version=2.0.0
#tool nuget:?package=Utils.EnvironmentManager&version=2.0.0

Utils.EnvironmentManager
The EnvironmentManager namespace now provides a class EnvManager that uses AutoMapper package, for retrieving environment variable values and performing type conversions.
Note This documentation assumes a basic understanding of
AutoMapperlibrary. AutoMapper docs
Initialization
To initialize the EnvManager, a configuration from AutoMapper is required:
var manager = EnvManager.CreateWithDefaultConfiguration();
Methods
GetEnvironmentValue
The method retrieves the value of the specified environment variable and converts it to the desired type using AutoMapper.
Signature:
public object GetEnvironmentValue(Type type, string variableName, bool raiseException = false)
Parameters:
type(Type): The type to which the environment variable's value should be converted.variableName(string): The name of the environment variable.raiseException(bool, optional): Specifies whether to raise an exception if the environment variable is null or empty, or when the conversion fails. Defaults to false.
Returns:
object: The converted value of the environment variable.
GetEnvironmentValue<T>
This method retrieves the value of the specified environment variable and converts it to the specified type T.
Signature:
public T GetEnvironmentValue<T>(string variableName, bool raiseException = false)
Parameters:
variableName(string): The name of the environment variable.raiseException(bool, optional): Specifies whether to raise an exception if the environment variable is null or empty, or when the conversion fails. Defaults to false.
Returns:
T: The converted value of the environment variable.
Adding Custom Mappings
The library now uses AutoMapper for type conversions.
Therefore, to add custom type conversions, you can utilize the EnvManagerMappingConfigurator class.
Example:
var config = new EnvManagerMappingConfigurator()
.CreateMapFor(x => DateTime.ParseExact(x, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture))
.CreateMapFor(x => Enum.Parse<MyEnumeration>(x, true))
.Build();
var manager = new EnvManager(config);
DateTime customDateFormat = manager.GetEnvironmentValue<DateTime>("CUSTOM_DATE_FORMAT");
In this example, a custom date format is added using the CreateMapFor method.
Also in this example adding mapping for a MyEnumeration enum.
Once the custom mappings are added, the configuration is built and passed to the EnvManager.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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. |
-
net6.0
- AutoMapper (>= 12.0.1)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Utils.EnvironmentManager:
| Package | Downloads |
|---|---|
|
ConfiguredSqlConnection
The NuGet package is a collection of utilities for working with SQL Server database connections using environment settings and secure connection strings. |
|
|
BNBParty.GraphQLClient
GraphQL Client for BNBParty .NET |
|
|
Poolz.Finance.CSharp.Strapi.Authorization
Library that handle API4 authorization process via GraphQL Strapi API. |
|
|
EthSmartContractIO.SecretsProvider
A EthSmartContractIO module, that facilitates the secure creation of an Ethereum account and the extraction of secrets. |
|
|
ConfiguredSqlConnection.Abstractions
Abstractions for configuring database connections using environment settings and secure connection strings. |
GitHub repositories
This package is not used by any popular GitHub repositories.
- Made EnvManager non-static.
- Included AutoMapper library for type conversion.