DotSettings.DependencyInjection
0.2.2
dotnet add package DotSettings.DependencyInjection --version 0.2.2
NuGet\Install-Package DotSettings.DependencyInjection -Version 0.2.2
<PackageReference Include="DotSettings.DependencyInjection" Version="0.2.2" />
<PackageVersion Include="DotSettings.DependencyInjection" Version="0.2.2" />
<PackageReference Include="DotSettings.DependencyInjection" />
paket add DotSettings.DependencyInjection --version 0.2.2
#r "nuget: DotSettings.DependencyInjection, 0.2.2"
#:package DotSettings.DependencyInjection@0.2.2
#addin nuget:?package=DotSettings.DependencyInjection&version=0.2.2
#tool nuget:?package=DotSettings.DependencyInjection&version=0.2.2

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
- If
RootPathis set, DotSettings searches up the directory tree for a.envfile (optional.env.tunnelalongside it). - Inside containers (
DOTNET_RUNNING_IN_CONTAINER=true), only the process environment is used. - 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
- .NET 10 (
net10.0) - DotEnv.Core (transitive via
DotSettings) - Microsoft.Extensions.DependencyInjection.Abstractions (only with
DotSettings.DependencyInjection)
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:
- On nuget.org Trusted Publishing, add a policy for owner
gabrieloliveirabrito, repoenvsettings, workflowpublish-nuget.yml, environmentnuget-publish. - In the GitHub environment
nuget-publish, set secretNUGET_USERto your nuget.org username (profile name, not email).
License
MIT — see LICENSE.
| Product | Versions 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. |
-
net10.0
- DotSettings (>= 0.2.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.