OK so im trying to create a settings class to store certain strings that i need to access throughout the system. I have created a globalSettings.cs with the code below:
public class GlobalSettings
{
private readonly Hashtable myHT;
public GlobalSettings()
{
//Hashtable used to store global strings
myHT = new Hashtable();
myHT.Add("logCategory","TMBC"); //event log category
myHT.Add("logSource", "MVC"); //event log source
//setup required options
//Create log source if required
if (!EventLog.SourceExists(myHT["logSource"].ToString()))
{
EventLog.CreateEventSource(myHT["logSource"].ToString(), myHT["logCategory"].ToString());
}
}
public string getSetting(string key)
{
return myHT.ContainsKey(key) ? myHT[key].ToString() : null;
}
}
At the moment i have initialised this class in each one of my controllers with the following:
protected GlobalSettings globalSettings = new GlobalSettings();
**Should i set the constructor to private and implement the singleton pattern as it is afterall a settings class and only need one instance?
Would i be better off extending the controller class with the setting information in it?
**