split unity configuration file

2019-07-07 08:18发布

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条回答
仙女界的扛把子
2楼-- · 2019-07-07 08:48

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" />
查看更多
登录 后发表回答