This is my app.config:
<appSettings>
<add key="PreRootFolder" value="D:\" />
<add key="RootFolder" value="webSite" />
<add key="Folder" value="folder_a" />
</appSettings>
Since I prefer to build the path in the application rather than have many keys for each part of the path… (hard to maintain) so I build the path this way:
string prePath = ConfigurationManager.AppSettings["PreRootFolder"];
string rootFolder = ConfigurationManager.AppSettings["RootFolder"];
string folder= ConfigurationManager.AppSettings["Folder"];
// global param (actually accessed by ((MainFormName)mainParent)).g_fullOriginalRoot
string g_fullOriginalRoot = prePath + "\\" + rootFolder + "\\" + fodler;
I do this in the application MDI parent form (so it never die)
I did this because I found out that I call those keys many times and now I can get the data from the parent.
I wonder, if my solution is correct?
Are app.config parameters loaded as globals?
It’s reasonable to use a globally accessible (static or singleton) object that memoises the settings in this case.
Many of the disadvantages of globals are less serious when communication is one-way (read-only settings or write-only logging being classic cases). Also, since the settings are inherently global, it matches what is being modelled.
I’d prefer to have this done in its own class than in the MDI form though. The form should model things that have to do with the form, other objects should model other concerns.