如何一次性刷新 .net 配置的所有部分或如何迭代它们?
有一些方法称为 ConfigurationManager.RefreshSection("..............");
它用于刷新 .net 配置中的部分,例如: ConfigurationManager.RefreshSection("connectionStrings");
我需要刷新一次配置的所有部分,我有一些想法: 使用 LINQ 或类似的东西迭代它们,但如何做到这一点!
There are some method called
ConfigurationManager.RefreshSection("..............");
It used to refresh sections in .net config for example: ConfigurationManager.RefreshSection("connectionStrings");
I need to refresh all sections of config one time, i have some idea:
To iterate through them using LINQ or something like that, but how to do that!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将配置视为依赖项。因此,不要将对
ConfigurationManager.ConnectionStrings
等的调用分散在应用程序代码中,而是开始与“注入”到应用程序中的Configuration
对象进行通信。如果您正在运行 IoC 容器,则可以通过依赖项注入来完成此操作,或者仅通过ConfigurationManager.OpenExeConfiguration()
读取它来完成。这样,您就可以随时替换整个
Configuration
对象,而无需刷新部分。Consider configuration as a dependency. So, in stead of having calls to
ConfigurationManager.ConnectionStrings
etc. scattered in your application code, start communicating with aConfiguration
object that is 'injected' in your application. This can be done by dependency injection, if you have an IoC container running, or just by reading it byConfigurationManager.OpenExeConfiguration()
.This way, you can replace the whole
Configuration
object any time you want, in stead of refreshing sections.