๐ WAYPOINT LESSON
Checkpoint โ The Layered Config Engine
โญโญ intermediateโณ 25 min read๐ Lesson 125 of 265
Combine JSON, environment overrides, typed options, and validation into one provider that fails fast and keeps secrets out of code.
The gate (mini-build)
A layered configuration engine โ the shape every real host uses:
JsonConfig(string json)โ parses{ "Section": { "Key": "value" } };Get("Section:Key")returns the value or null.LayeredConfig(IConfigProvider file, string envPrefix)โ looks up env first (envPrefix__SECTION__KEY, upper-cased,:โ__), then falls back to the file provider.BindRetry(IConfigProvider config)โ typedRetryOptions(defaults 3 / 200) readingRetry:MaxAttemptsandRetry:DelayMsas ints, with non-numeric values throwing FormatException.Validate(RetryOptions)โ MaxAttempts >= 1, DelayMs >= 0; all problems in one message:"Retry: <p1>; <p2>".- Secrets rule baked in:
Require(config, key)returns the value or throwsInvalidOperationException("Configuration key <key> is required")โ no fallbacks.
Provided: IConfigProvider / MemoryConfig (same as the practice).