ASP.NET Core managed config
Part of my ASP.NET Core recipe series: binding appsettings.json to typed config classes so settings are managed code instead of magic strings.
5 articles in the notebook
Part of my ASP.NET Core recipe series: binding appsettings.json to typed config classes so settings are managed code instead of magic strings.
Reading appSettings shouldn't require custom sections, XML readers or per-access string conversion. A small base class that maps keys like Config.SmtpClient.Host to a typed tree, converted once at startup.
Forgetting to swap config files at deployment can be disastrous. This approach keeps all environment configs in one file, selects the right one automatically, and uses ACLs so developers can't read production secrets.
A .dll shared between web and desktop apps can't assume where app.config or web.config lives. A small cached method that resolves the correct config file wherever the assembly is running, with Nini example.
.NET tools to use, part two: Nini, an uncommonly powerful configuration library. Reads web.config, .ini and .xml config with type conversion and default values in a couple of lines.