简体   繁体   English

检索配置管理器加载的所有配置设置

[英]retrieve all configuration settings that are loaded by the configuration manager

Is there any way to enumerate through all settings to get the values that have been loaded by the configuration manager? 有什么方法可以枚举所有设置以获得配置管理器已加载的值? Maybe I'm being dense here, but I can't find a way to enumerate through the settings that are contained within a section group. 也许我在这里很忙,但是我找不到找到枚举组中包含的设置的方法。

I have a WCF service which is a designed to allow the calling system to pass in request objects which define the operation to be performed on the server. 我有一个WCF服务,该服务旨在允许调用系统传递请求对象,这些对象定义了要在服务器上执行的操作。 The service loads assemblies dynamically at runtime (like a plug-in model) and determines which object can answer the request. 该服务在运行时动态加载程序集(例如插件模型),并确定哪个对象可以回答请求。 I am looking for a way that I can send a request to "give me all your config info", and the service can return the loaded information. 我正在寻找一种方法,可以发送请求“给我您所有的配置信息”,并且该服务可以返回已加载的信息。 I'm interested in what has been loaded into memory and is being used vs. what values are specified in the actual config file (the config can be replaced without affected anything in memory until a restart). 我对已加载到内存中的文件以及正在使用的文件和实际配置文件中指定的值感兴趣(可以重新配置而不影响内存中的任何内容,直到重新启动为止)。

There's a SettingLoaded event that I might be able to use to keep track of them, but this seems far-fetched. 我可以使用一个SettingLoaded事件来跟踪它们,但这似乎牵强。

Any ideas? 有任何想法吗?

[UPDATE] The main purpose for this question is that I need a way to determine the difference between the settings contains within an assemblies physical .config file vs the setting that are compiled into the assembly as part of the "default" config. [更新]此问题的主要目的是,我需要一种方法来确定程序集物理.config文件中包含的设置与作为“默认”配置的一部分编译到程序集中的设置之间的差异。

I can't just use the physical config file as the starting point for the comparison, because there may not be a config file present, or the config file may only provide one of the values, causing the others to use their default value. 我不能仅仅使用物理配置文件作为比较的起点,因为可能不存在配置文件,或者配置文件可能仅提供其中一个值,从而导致其他人使用其默认值。

可能是我误解了您的问题,但是对我而言,唯一可以保证是键/值对的设置是AppSettings ,您可以通过ConfigurationManager.AppSettings属性来获取。

It sounds like you're basically wanting to have a registration system for plug-ins. 听起来您基本上是想拥有一个插件注册系统。 It also sounds like you're trying to diff what's in memory vs. what's loaded because you want to detect when the registration has changed without restarting? 听起来还好像您在尝试比较内存中的内容与加载的内容,因为您想检测何时更改了注册而不重新启动?

If those are true , one option is to create your own registration xml file and use the FileWatcher class to get an event when the file has changed then you can reload the registration info. 如果这些设置为true ,则一个选择是创建您自己的注册xml文件,并使用FileWatcher类在文件更改后获取事件,然后可以重新加载注册信息。

Maybe the solution here is a change in process/procedure so that all config-based settings are to be explicitly provided via a config file. 也许这里的解决方案是更改流程/过程,以便通过配置文件显式提供所有基于配置的设置。 This could be ensured by always providing a breaking or "known-bad" value for any setting's default value. 可以通过始终为任何设置的默认值提供断点或“已知坏”值来确保这一点。 This would ensure that valid values must be provided by a config file. 这将确保必须由配置文件提供有效值。 This approach would allow a comparison of values using the config file as the comparison source. 这种方法将允许使用配置文件作为比较源来比较值。

The drawback to this approach is that all config settings have to be merged into the primary assembly's config file in order for the values to take effect. 这种方法的缺点是必须将所有配置设置合并到主程序集的配置文件中才能使值生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM