Should you consider the use of Properties.Settings.Default within a class as a dependency, and therefore inject it?
e.g.:
public class Foo
{
private _settings;
private bool _myBool;
public Foo(Settings settings)
{
this._settings = settings;
this._myBool = this._settings.MyBool;
}
}
.
.
or would you consider the use of Settings as an application wide global as good practice?
e.g.:
public class Foo
{
private bool _myBool;
public Foo()
{
this._myBool = Properties.Settings.Default.MyBool;
}
}
You may want to encapsulate Settings in a class and have an interface for them. This way, where your settings are coming from can be changed for things like unit testing. If you’re also using an IoC container, then by all means register the settings with the container.
I do this for the
ConfigurationManagerandWebConfigurationManagerso that I can inject settings for tests. Nathan Gloyn has wrapped the adapters and interface up already in a project that you can use if you also want to do this.