.NET own configuration file

陌路散爱 提交于 2019-12-03 13:37:29

I found this and it works. "path" is a path to configuration file.

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);

Not directly.

Indirectly, you could:

  • spin up a second AppDomain, specify the config-file for that (AppDomainSetup.ConfigurationFile), and execute the code in the app domain
  • have two exes; the first (foo.exe) simply copies the config (into bar.exe.config) and shells the 2nd exe (bar.exe) [warning: thread race]

If you're using log4net you can specify your configuration file in the AssemblyInfo.cs

ThorHalvor

Another solution is to refactor and create your own ConfigurationRepository. Then you can change at runtime what specific repository implementation you will use.

For example, AppConfigRepository : ConfigurationRespository will just be a facade for the old ConfigurationManager.AppSettings["key"].

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!