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主要是用于配置接口的默认实现,如果想修改某个接口的
  • 相关阅读:
    mysql中如何根据id,一次查询对应id的数据
    DataFrame中merge、concat、join,以及用一个data更新另一个data的方法
    pandas中drop_duplicates用法
    DataFrame中根据某字段选取重复字段数据
    金融数据处理过程中的一些小tip
    pandas中某一列的值满足一定条件就改变
    MIKE指标
    python 数据处理中的记录
    python绘制主次坐标图
    python学习笔记之四-多进程&多线程&异步非阻塞
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760239.html
Copyright © 2011-2022 走看看