We have three ways to split a large configuration file into multiple small configuration files. Here is the introductions.
-
<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.
-
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.
-
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>