![]() |
VOOZH | about |
dotnet add package Envy --version 1.2.0
NuGet\Install-Package Envy -Version 1.2.0
<PackageReference Include="Envy" Version="1.2.0" />
<PackageVersion Include="Envy" Version="1.2.0" />Directory.Packages.props
<PackageReference Include="Envy" />Project file
paket add Envy --version 1.2.0
#r "nuget: Envy, 1.2.0"
#:package Envy@1.2.0
#addin nuget:?package=Envy&version=1.2.0Install as a Cake Addin
#tool nuget:?package=Envy&version=1.2.0Install as a Cake Tool
A utility library for loading environment variables into strongly-typed C# objects.
Inspired by the Rust crate of the same name.
using Envy;
// create a special Env instance with the prefix "DB"
// now all variable accesses will be prefixed with "DB_" automatically
var env = Env.Vars.WithPrefix( "DB" );
// set some environment variables
// typically these would already be set in your environment
// but for the sake of this example, we'll set them here
// because of the prefix on env, the variables will be set as DB_HOST, DB_USER, and DB_PASS
env["HOST"] = "example.com";
env["USER"] = "admin";
// Env will automatically convert the case of the variable names to upper case
// so on our prefixed env, the variable name passed here is 'Pass' but it will internally resolve to 'DB_PASS'
env[nameof( DatabaseConnectionInfo.Pass )] = "hunter2";
// the underscore separator (or whatever separator you specify on Env.PrefixSeparator) is inserted automatically.
// DB is our prefix that goes before the variable name, separated by an Env.PrefixSeparator
// the prefix argument is optional and defaults to null for no prefix.
var connInfo = Env.Bind<DatabaseConnectionInfo>( "DB" );
// connInfo now looks like this:
// ╭──────────┬───────────────╮
// │ Name │ Value │
// ├──────────┼───────────────┤
// │ Host │ "example.com" │
// │ Port │ 27017 │
// │ User │ "admin" │
// │ Pass │ "hunter2" │
// │ Database │ null │
// ╰──────────┴───────────────╯
// connect to MongoDB
public sealed record DatabaseConnectionInfo
{
public required string Host { get; init; }
[Optional] public ushort Port { get; init; } = 27017;
public string? User { get; init; }
public string? Pass { get; init; }
public string? Database { get; init; }
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.