Several places in my code a serviceurl is retrievet from app.config like this ConfigurationManager.AppSettings["ServerURL"];
Now I would like to make it possible to the users to specify the service url as a commandline argument. If no argument is specified the serviceurl from app.config must be used.
In Main I can do the following:
if(args[0] != null)
ConfigurationManager.AppSettings["ServerURL"] = args[0]
It seems to work, but can i rely on that AppSettings[“ServerURL”] isnt reloaded from app.config? I know about ConfigurationManager.RefreshSection but it isnt used.
Instead of changing the
AppSettingsvalues from code, you should have another class that wrapsConfigurationManagerand provides the logic for the value replacement:And in
Main():This will also simplify unit testing.