I really suggest wrapping any βget settingsβ function in the object and hiding it behind the interface. We are gaining this much, so we have:
public class Worker { private readonly ISettings settings; public Worker (ISettings settings) { this.settings = settings; } public void Work () { for (int i = 0; i < settings.MaxWorkerIterations (); i++) { ... } } } public interface ISettings { int MaxWorkerIterations (); } public class AppConfigSettings { public int MaxWorkerIterations () { return (int) ApplicationSettings["MaxWorkerIterations"]; } }
This has the advantage of (mostly) compile time checking and ease of testing. You can also override the AppConfigSettings class as the CachingAppConfigSettings class, which makes it obvious.
source share