We have three ways to split a large configuration file into multiple small configuration files. Here is the introductions.

  1. <linkedConfiguration>
    The main limitation of this way is the <linkedConfiguration> element is not supported for applications with Windows side-by-side manifests. We can refer to MSDN to get more information.
  2. System.Configuration.ConfigurationManager or System.Web.Configuration.WebConfigurationManager
    The main defect is we must design an architecture by ourself for supporting this. We can refer to MSDN to get more information.
  3. Using configSource
    Base on my understanding, this is the best way, we can avoid the previous two defects by the way. Here is my example. I use Unity Application Block of Microsoft Enterpriese Library in the example; I separated unity configuration file into another file under a sub folder.
     Learning.WebApplication
    {
        public partial class _Default : System.Web.UI.Page
        {
            
    protected void Page_Load(object sender, EventArgs e)
            {
                IUnityContainer unityContainer 
    = new UnityContainer();
                UnityConfigurationSection section 
    = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
                section.Containers.Default.Configure(unityContainer);

                Test obj 
    = unityContainer.Resolve<Test>();
                
    if (obj == null)
                    Response.Write(
    "null");
                
    else
                    Response.Write(obj.GetType().ToString());
            }
        }

        
    public class Test { }
    }


      <configSections>
        
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      
    </configSections>
      
    <unity configSource="App_Data\Unity.config" />
    </configuration>


      <typeAliases>
        
    <typeAlias alias="Test" type="Learning.WebApplication.Test, Learning.WebApplication" />
      
    </typeAliases>
      
    <containers>
        
    <container>
          
    <types>
            
    <type type="Test" />
          
    </types>
        
    </container>
      
    </containers>
    </unity>

相关文章:

  • 2022-01-11
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-19
  • 2022-03-09
  • 2021-08-04
  • 2022-02-15
  • 2021-07-20
  • 2021-07-20
相关资源
相似解决方案