• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
周巍
学习生活,学习技术,也学习英语
博客园    首页    新随笔    联系   管理    订阅  订阅

Split configuration file into multiple files

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.
    Code
    namespace 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 { }
    }

    Web.config (Partial)
    <?xml version="1.0"?>
    <configuration>
      
    <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>

    Unity.config
    <?xml version="1.0" ?>
    <unity>
      
    <typeAliases>
        
    <typeAlias alias="Test" type="Learning.WebApplication.Test, Learning.WebApplication" />
      
    </typeAliases>
      
    <containers>
        
    <container>
          
    <types>
            
    <type type="Test" />
          
    </types>
        
    </container>
      
    </containers>
    </unity>
posted @ 2009-01-06 22:29  周巍  阅读(1721)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3