split unity configuration file

柔情痞子 提交于 2019-12-10 18:08:12

问题


I need to split my unity configuration into n different files so i can select it some of those files into the same unity container??


回答1:


OK. It's too late but I could answer. You need something like this:

    private IUnityContainer ReadContainer()
    {
        var unityCommon = (UnityConfigurationSection)ConfigurationManager.GetSection("unityCommon");
        IUnityContainer returnValue = new UnityContainer();
        unityCommon.Configure(returnValue, "Common"); // Unnamed <container> element
        var unitySpecific = (UnityConfigurationSection)ConfigurationManager.GetSection("unitySpecific");
        unitySpecific.Configure(returnValue, "Specific"); // 
        return returnValue;
    }

And have this in app.config:

  <configSections>
        <section name="unityCommon" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
        <section name="unitySpecific" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
  </configSections>

  <unityCommon configSource="unity.common.config.xml" />


来源:https://stackoverflow.com/questions/2555539/split-unity-configuration-file

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