1

I need to break application settings in two files, one for external resources access, like a share folder or a web service url, and other for all the rest.

To keep configuration access simple in code i added a new Settings file, called ExternalResourceSettings. These settings files are derive from ApplicationSettingsBase.

How can i load an object of this class from a specific configuration file?

For clarification, the ExternalResourceSettings looks like these:

internal sealed partial class ExternalResourceSettings: global::System.Configuration.ApplicationSettingsBase {
...
}

ConfigurationManager class can load any config file to a Config object in 3 lines:

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();                    
configFileMap.ExeConfigFilename = "Some path";

// Get the mapped configuration file
var config =ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

But how to convert it to ExternalResourceSettings? Or can ExternalResourceSettings be loaded from a specific file in a other way?

Note: ExternalResourceSettings default constructor reads from default configuration file.

5
  • have a look at this or this Commented Nov 19, 2019 at 14:20
  • The solution presented is kind of brute force solution: Wrap all settings, one by one, in another class. I am looking for some solution built-in the framework to avoid doing all that work. Commented Nov 19, 2019 at 14:39
  • Here as well it says the same thing Commented Nov 19, 2019 at 16:14
  • if you could use appsettings.json for ExternalResourceSettings, this could work.. Commented Nov 19, 2019 at 16:15
  • Yes, but is not a strong typed solution and not even avoids to use strings for keys. A wrapper class gives works but is better than just use appSettings. It is odd how there is no native solution. I am looking for packages now, packages that may extend configuration in this way. Commented Nov 19, 2019 at 16:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.