Production engineering
using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
int current=3; bool Accept(int candidate) { if(candidate is <1 or >10)return false; current=candidate; return true; }
Console.WriteLine("accepted:"+Accept(5)); Console.WriteLine("current:"+current); Console.WriteLine("accepted:"+Accept(0)); Console.WriteLine("current:"+current);
Reveal answer and reasoning
The output lines, in order, are “accepted:True”; “current:5”; “accepted:False”; “current:5”. The portable .NET9 console companion implements an explicit policy around an integer current value. Accept checks whether its candidate lies between one and ten before assignment. Accepting five prints accepted:True and current:5; rejecting zero prints accepted:False and leaves current:5. This code genuinely preserves its previous value because the assignment is after validation.
It contains no configuration provider, file watcher, options cache or background callback. Its output must not be attributed to IOptionsMonitor's automatic behavior. It demonstrates the additional publication rule an application might choose to build around a source of changing candidates.
File notification, parsing, option construction, validation and consumer access are distinct steps with their own failures. A valid reload test does not establish that an invalid update retains the previous valid object or consistently produces503. Provider ordering also determines which configuration source wins; this example should be read as its actual configured source graph rather than a universal precedence recipe.
The demonstration secret is explicitly not a credential. Reporting hasSecret still discloses presence, and excluding the string from one response does not remove it from the local file, memory or an unrelated logging pipeline.
What a strong answer covers
- Exact output: accepted:True | current:5 | accepted:False | current:5
- The portable .NET9 console companion implements an explicit policy around an integer current value.
- File notification, parsing, option construction, validation and consumer access are distinct steps with their own failures.
Common pitfall
File notification, parsing, option construction, validation and consumer access are distinct steps with their own failures. A valid reload test does not establish that an invalid update retains the previous valid object or consistently produces503. Provider ordering also determines which configuration source wins; this example should be read as its actual configured source graph rather than a universal precedence recipe. The demonstration secret is explicitly not a credential. Reporting hasSecret still discloses presence, and excluding the string from one response does not remove it from the local file, memory or an unrelated logging pipeline.
Follow-up questions
- How would two processes prove they are using the same accepted configuration revision during a staged rollout?
- Why would a catch around CurrentValue not establish that every invalid reload callback is handled safely?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.