To begin I have a .NET 2.0 console application. To meet a customer requirement, I need to use a configuration file which is in a different directory than my application in a read/write manner. This is in addition to the exe configuration which my app already has (ie appname.exe.config).
So to do this, I added a property Configuration which returns a Configuration object obtained from a call to OpenMappedExeConfiguration().
I'm trying to step back an re-evaluate this implementation. What I wrote seems really hackish. Is this even the right approach? I read through a lot of material on .net configuration files, but I'm still not sure exactly what I should do.
class LocalEnvironment {
... stuff
static Configuration _cfg;
internal static Configuration Configuration {
get {
if (_cfg == null) {
var fm = new ExeConfigurationFileMap
{
ExeConfigFilename = Path.Combine(ApplicationInstallDirectory,
"config.xml")
};
_cfg = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None);
}
return _cfg;
}
}
}