zoukankan      html  css  js  c++  java
  • 应用Castle容器到实际项目中

           最近在实际项目中应用了Castle容器实现Ioc设计模式,在项目中很方便地进行接口编程,大大提高程序的可扩展性,已经成功在一个数据库压力测式工具、Web服务压力测试工具和权限管理框架上进行成功的应用。
           1、首先为了更方便的创建IWindsorContainer接口并且从外部xml配置文件而不是web.config中加载配置信息,创建一个ContainerBuilder类进行简单的封装:

        public static class ContainerBuilder
        
    {
            
    private static readonly object ton = new object();
            
    private static IWindsorContainer container = null;

            
    public static IWindsorContainer Create()
            
    {
                
    string fileName = "Components.config";
                HttpContext context 
    = HttpContext.Current;
                
    if (context != null)
                
    {
                    fileName 
    = context.Server.MapPath("~/App_Data/Components.config");
                }


                
    if (container == null)
                
    {
                    
    lock (ton)
                    
    {
                        
    if (container == null)
                        
    {
                            container 
    = new WindsorContainer(new XmlInterpreter(fileName));
                        }

                    }

                }


                
    return container;
            }

        }

    2、同时我了更方便的实现通过修改配置文件便能切换具体接口的实现,创建IContainerDefaultImplement和它的实现ContainerDefaultImplement主要是用于配置接口的默认实现,如果想修改某个接口的
  • 相关阅读:
    [转]对Lucene PhraseQuery的slop的理解
    Best jQuery Plugins of 2010
    15 jQuery Plugins To Create A User Friendly Tooltip
    Lucene:基于Java的全文检索引擎简介
    9 Powerful jQuery File Upload Plugins
    Coding Best Practices Using DateTime in the .NET Framework
    Best Image Croppers ready to use for web developers
    28 jQuery Zoom Plugins Creating Stunning Image Effect
    VS2005 + VSS2005 实现团队开发、源代码管理、版本控制(转)
    禁止状态栏显示超链
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760239.html
Copyright © 2011-2022 走看看