我正在尝试从名为“Config”的另一个程序集加载Unity的配置设置,但是我没有太多的运气。
var fileMap = new ConfigurationFileMap("assembly://Config/Config/Unity.config");
System.Configuration.Configuration configuration = onfigurationManager.OpenMappedExeConfiguration(fileMap as ExeConfigurationFileMap, ConfigurationUserLevel.None);
var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
有什么建议吗?
答案 0 :(得分:1)
尝试将其作为解决方法。
在您的代码中:
var container = new UnityContainer();
var path = ConfigurationManager.AppSettings["UnityPath"].ToString();
var map = new ExeConfigurationFileMap();
map.ExeConfigFilename = path;
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");
在您的配置文件中:
<appSettings>
<add key ="UnityPath" value="C:\PathToYourConfigFile\Unity.Config"/>
</appSettings>