Skip to main content
๐Ÿ“œ 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:

  1. JsonConfig(string json) โ€” parses { "Section": { "Key": "value" } }; Get("Section:Key") returns the value or null.
  2. LayeredConfig(IConfigProvider file, string envPrefix) โ€” looks up env first (envPrefix__SECTION__KEY, upper-cased, : โ†’ __), then falls back to the file provider.
  3. BindRetry(IConfigProvider config) โ†’ typed RetryOptions (defaults 3 / 200) reading Retry:MaxAttempts and Retry:DelayMs as ints, with non-numeric values throwing FormatException.
  4. Validate(RetryOptions) โ€” MaxAttempts >= 1, DelayMs >= 0; all problems in one message: "Retry: <p1>; <p2>".
  5. Secrets rule baked in: Require(config, key) returns the value or throws InvalidOperationException("Configuration key <key> is required") โ€” no fallbacks.

Provided: IConfigProvider / MemoryConfig (same as the practice).