哭佛林

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
ServiceLocator类对配置文件各种配置位置的集中管理:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace Kufolin.DBUtility
{
    
/// <summary>
    
///  类 编 号: 03
    
///  类 名 称: ServiceLocator
    
///  内容摘要: 对配置文件各种配置位置的集中管理
    
///  完成日期: 2007-12-9 17:37:38
    
///  编码作者: 田长军
    
///  </summary>

    public sealed class ServiceLocator
    
{
        
public ServiceLocator() { }
        
/// <summary>
        
/// 各个IDAL对象所在的命名空间路径
        
/// </summary>

        private static readonly string dalPath = ConfigurationManager.AppSettings["ProjectDAL"];
        
/// <summary>
        
/// Model对象所在的命名空间路径
        
/// </summary>

        private static readonly string modelPath = ConfigurationManager.AppSettings["ModelAssembly"];
        
/// <summary>
        
/// 连接字符串
        
/// </summary>

        private static readonly string sqlPath = ConfigurationManager.ConnectionStrings["SQLConnString"].ConnectionString;
        
/// <summary>
        
/// 对DAL层的反射机制封装
        
/// </summary>
        
/// <param name="className">需生成的类名</param>
        
/// <returns>生成的类对象</returns>

        public static object LocateDALObject(String className)
        
{
            
string fullPath = dalPath + "." + className;
            
return Assembly.Load(dalPath).CreateInstance(fullPath);
        }

        
/// <summary>
        
/// 返回Model的路径
        
/// </summary>
        
/// <returns>Model的路径</returns>

        public static String LocateModelPath()
        
{
            
return modelPath;
        }

        
/// <summary>
        
/// 返回Sql连接字符串
        
/// </summary>
        
/// <returns>Sql连接字符串</returns>

        public static String LocateSqlPath()
        
{
            
return sqlPath;
        }

    }

}

posted on 2008-01-30 09:45  哭佛林<Kufolin>  阅读(687)  评论(0)    收藏  举报