One way to approach this problem is to knock it out due to a DAL problem .
No matter what class / webpage, etc. should use the configuration settings, declare a dependency on IConfigSettingsService (factory / repository / whatever you want to use).
private IConfigSettingsService _configSettingsService; public WebPage(IConfigSettingsService configSettingsService) { _configSettingsService = configSettingsService; }
Thus, your class will receive the following settings:
ConfigSettings _configSettings = _configSettingsService.GetTheOnlySettings();
the implementation of ConfigSettingsService will have a dependency, which is a Dal class. How would this Dal populate a ConfigSettings object? Who cares.
Perhaps it will populate ConfigSettings from the database or XML .config file each time.
Perhaps he does this for the first time, and then populates the static _configSettings for subsequent calls.
Perhaps he will get the settings from Redis. If something indicates a change in settings, then dal or something external can update Redis. (This approach will be useful if you have several applications using settings.
No matter what it does, your only addiction is the non-Internet service interface. It is very easy to taunt. In your tests, you can return ConfigSettings to it with what you want in it).
In reality, most likely this is MyPageBase, which has an IConfigSettingsService dependency, but it can also be a simple web service, a Windows service, somehatsit MVC, or all of the above.
Jordan morris
source share