My question is about working with standard .NET configuration objects and custom configuration elements as well, (which one can define by extending the System.Configuration.ConfigurationSection
class). We usually obtain these from the System.Configuration.ConfigurationManager
class's methods, GetSection(...)
being an example.
The loaded configuration object appears to be a merged configuration object containing the setup present in the application config file (the the app.config or web.config file which a developer may have created) and what is defined in the machine.config file (the latter coming with the .NET Framework installation).
So, we can assume that the configuration is loaded in hierarchical manner with the machine.config first, and any user-defined configuration overlaying that default setup, and could be looked at like this:
- machine.config
- app.config (overrides / merges with respective elements found in machine.config )
My goal is to create multiple layers of configuration, so that there might be other config files between (and if possible, after) the machine.config and the app.config file:
- machine.config
- custom.config (a custom config interfering between the machine.config and the app.config file)
- app.config - now app.config is merged with both machine.config and custom.config
- custom.config (a custom config interfering between the machine.config and the app.config file)
Normally, I would write my own configuration manager class and will try to get as far as I could to get the desired result, but assuming the .NET framework has this working for machine.config and app.config, I thought I might benefit from the built-in functionality of the framework. In addition, I do not know how to manually trigger such merging, if I am indeed supposed to resort to a config manager implementation of my own.
So, is it possible to leverage the built-in mechanisms of configuration section/element merging with custom configuration files? I am especially interested in developing and supporting this for custom configuration sections. The System.Configuration
namespace contains base objects to build configuration section and elements, and those allow some settings related to the merging (like setting the appropriate ConfigurationElementCollectionType
for example). Are these related to only merging with machine.config (or multiple layers of web.config files in a web application), or is it possible to manually trigger the merging of pre-loaded config files?
Note: I would appreciate better a solution that would work on .NET 3.0+. Please add a note if your answer targets a higher version of the framework.
Aucun commentaire:
Enregistrer un commentaire