Skip to main content

Practice · 1 of 3

The Environment Provider

CHALLENGE
Difficulty: intermediate+25 XP

Build a prefix-scoped provider over environment variables: Get(name) looks up "<PREFIX>__<NAME>" (double-underscore), returning null when unset. GetInt(name) parses to int and throws FormatException with the raw value when not a number. Tests control the environment in-process. ``csharp public sealed class EnvConfig { public EnvConfig(string prefix); // e.g. "CJ" public string? Get(string name); public int GetInt(string name); // throws FormatException on junk } ``

Back to lesson: Practice: Config Practice: Providers, Binding, Secrets