DotSettings.DependencyInjection 0.2.2

dotnet add package DotSettings.DependencyInjection --version 0.2.2
                    
NuGet\Install-Package DotSettings.DependencyInjection -Version 0.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotSettings.DependencyInjection" Version="0.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotSettings.DependencyInjection" Version="0.2.2" />
                    
Directory.Packages.props
<PackageReference Include="DotSettings.DependencyInjection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotSettings.DependencyInjection --version 0.2.2
                    
#r "nuget: DotSettings.DependencyInjection, 0.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotSettings.DependencyInjection@0.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotSettings.DependencyInjection&version=0.2.2
                    
Install as a Cake Addin
#tool nuget:?package=DotSettings.DependencyInjection&version=0.2.2
                    
Install as a Cake Tool

DotSettings

DotSettings

Typed application settings bound from .env files and process environment variables.

DotSettings is a small .NET library: you declare settings classes with [EnvKey] / [EnvSubConfiguration], call Env.Load<THost>(), and get validated instances in a catalog, via .Shared, and optionally as DI singletons.

It does not ship app-specific schemas, database drivers, Redis clients, or connection-string converters. Your application owns those.

Install

Core (no DI dependency):

dotnet add package DotSettings

ASP.NET / Microsoft.Extensions.DependencyInjection integration:

dotnet add package DotSettings.DependencyInjection

Quick start

using DotSettings;
using Microsoft.Extensions.DependencyInjection;

public sealed class DatabaseSettings : DotSettings<DatabaseSettings>
{
    [EnvKey("DATABASE_URL")]
    public string ConnectionString { get; set; } = "";

    [EnvKey("DATABASE_POOL_SIZE")]
    public int? PoolSize { get; set; } // optional
}

public sealed class AppHostSettings
{
    [EnvSubConfiguration]
    public DatabaseSettings Database { get; set; } = new();
}

// Early in Program.cs — before building the host if you need settings for logging, etc.
Env.Load<AppHostSettings>(new Env.LoadOptions
{
    RootPath = AppContext.BaseDirectory, // walks parents looking for .env
    LogToConsole = true,
});

// Same instance everywhere:
var conn = DatabaseSettings.Shared.ConnectionString;
var again = DotSettingsCatalog.GetSettings<DatabaseSettings>().ConnectionString;

// Requires DotSettings.DependencyInjection
var services = new ServiceCollection();
services.AddDotSettings(); // registers catalog types as singletons

Rules of thumb

Rule Behavior
Property with [EnvKey("NAME")] Bound from .env (non-empty) or process env
Non-nullable property Missing key → EnvConfigurationException (fail fast)
Nullable property (string?, int?, …) Missing key → left as default / null
Property without attributes Ignored by the binder
[EnvSubConfiguration] Nested settings node (recursion + catalog registration)

Refresh

Env.Refresh() re-reads the .env into a scratch graph. On success it copies values into the live Shared instances; on failure it logs and leaves Shared unchanged.

Testing

Env.ResetForTesting();
Env.LoadPrepared(host); // register instances without reading files

How values are resolved

  1. If RootPath is set, DotSettings searches up the directory tree for a .env file (optional .env.tunnel alongside it).
  2. Inside containers (DOTNET_RUNNING_IN_CONTAINER=true), only the process environment is used.
  3. For each key: non-empty value from the file map wins; otherwise the process environment; otherwise the key is missing.

Inline comments outside quotes are stripped (VALUE # note → VALUE).

Logging overrides helper

LogLevelsParser parses strings like Microsoft:Warning;MyApp:Info into IReadOnlyDictionary<string, SystemLogLevel>. Bind a property of that dictionary type with [EnvKey("LOG_LEVELS")] and the binder uses the parser automatically.

Bootstrap messages from this library use EnvBootstrapLog / EnvLogLevel (pluggable sink, default Console) — separate from your app logger.

Requirements

Release process

PRs targeting development must include exactly one version label:

Label Bump
patch 0.1.0 → 0.1.1
minor 0.1.0 → 0.2.0
major 0.1.0 → 1.0.0

On merge, CI bumps VERSION (shared by both NuGet packages). Publishing to NuGet is a manual workflow (publish-nuget) restricted to maintainers, using Trusted Publishing (OIDC) — no long-lived API key.

Setup once:

  1. On nuget.org Trusted Publishing, add a policy for owner gabrieloliveirabrito, repo envsettings, workflow publish-nuget.yml, environment nuget-publish.
  2. In the GitHub environment nuget-publish, set secret NUGET_USER to your nuget.org username (profile name, not email).

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2 138 9/21/2026
0.2.1 98 9/21/2026
0.2.0 109 9/21/2026