On a ASP.NET MVC application with multiple assemblies I need to access a few settings.
Basically. the settings are constants or values from Web.Config AppSettings.
My idea is to inject a Settings
class, as a singleton, in places where I need it:
public interface ISettings {
LoggerSettings Logger { get; }
} // ISettings
public class LoggerSettings {
public String Levels { get { return ConfigurationManager.AppSettings["Logger.Levels"]; } }
public const String Report = "team@xyz.com";
} // LoggerSettings
public class Settings : ISettings {
public LoggerSettings Logger { get; private set; }
public Settings() {
Logger = new LoggerSettings();
}
} // Settings
What do you think about this approach and injecting the class as a singleton?
Do I need, in this case, to set any class/property as static? I think I need to have LoggerSettings and its properties as static, not? Otherwise I will need to create a new instance when constructing the Settings?
Could someone, please, advise me on this?