
[英].Net configuration - How to override settings and custom sections in a mapped configuration file?
[英]How to refresh all sections of .net configuration one time or how to iterate through them?
有一些方法称为ConfigurationManager.RefreshSection(“ ..............”);
例如,它用于刷新.net config中的节:ConfigurationManager.RefreshSection(“ connectionStrings”);
我需要一次刷新配置的所有部分,我有一个主意:使用LINQ或类似方法遍历它们,但是如何做到这一点!
将配置视为依赖项 。 因此,与其分散在应用程序代码中的对ConfigurationManager.ConnectionStrings
等的调用,不如与“注入”到您的应用程序中的Configuration
对象进行通信。 如果您正在运行IoC容器,则可以通过依赖项注入来完成,也可以仅通过ConfigurationManager.OpenExeConfiguration()
读取它来完成。
这样,您可以随时替换整个Configuration
对象,而不用刷新部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.