三层架构

一、架构图

二、解决方案中的项目设计 

AbstractFactory(抽象工厂) 

IBLL(业务逻辑层) 

BLL

IDAL(数据访问层) 

SqlServerDAL(SqlServer数据访问) 

```` 

Model(数据模型) 

ToolsLibrary(工具类) 

WebMVCApplication(Web MVC应用程序) 

三、具体的实现

1、AbstractFactory 

(1)Cache.cs 反射出实例很耗费性能,这里使用缓存来减轻负担 

///   <summary>
///  抽象工厂的实现,因为反射出实例很耗费性能,所以运用了缓存来减轻负担
///   </summary>
public   class  Cache
{
     public  Cache()
    {

    }
     ///   <summary>
     ///  获取缓存数据
     ///   </summary>
     ///   <param name="key"> key </param>
     ///   <returns></returns>
     public   static   object  Get( string  key)
    {
        System.Web.Caching.Cache cache = HttpRuntime.Cache;
         return  cache.Get(key);
    }
     ///   <summary>
     ///  添加缓存数据
     ///   </summary>
     ///   <param name="key"> key </param>
     ///   <param name="value"> value </param>
     public   static   void  InsertCache( string  key,  object  value)
    {
         if  (Get(key) ==  null )
        {
            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            cache.Insert(key, value);
        }
    }
}

(2)DALFactory.cs 反射DAL,使用IOC依赖注入

public   class  DALFactory
{
     ///   <summary>
     ///  DLL全路径
     ///   </summary>
     public   static   readonly   string  DALPath = System.Configuration.ConfigurationManager.AppSettings[ " DALPath " ];
     public   static   object  CreateDAL( string  assemblyPath,  string  objType)
    {
         var  cacheDAL = Cache.Get(objType);
         if  (cacheDAL ==  null )
        {
            cacheDAL = Assembly.Load(assemblyPath).CreateInstance(objType);
            Cache.InsertCache(objType, cacheDAL);
        }
         return  cacheDAL;
    }
     public   static  IDAL.IExample GetExampleDAL()
    {
         return  CreateDAL(DALPath,  string .Format( " {0}.Example " , DALPath))  as  IDAL.IExample;
    }
}

2、IBLL 

public   interface  IExampleService
{
     int  Add(Model.Example model);

} 

3、BLL 

public   class  ExampleService : IBLL.IExampleService
{
     public  ExampleService()
    {
         this .exampleDAL = AbstractFactory.DALFactory.GetExampleDAL();
    }
     ///   <summary>
     ///  数据表数据访问层接口
     ///   </summary>
     private  IDAL.IExample exampleDAL;
     public  IDAL.IExample ExampleDAL
    {
         set  { exampleDAL = value; }
         get  {  return  exampleDAL; }
    }
     public   int  Add(Model.Example model)
    {
         return  exampleDAL.Add(model);
    }

} 

4、IDAL

///   <summary>
///  接口层 IExample
///   </summary>
public   interface  IExample
{
     #region  成员方法
     ///   <summary>
     ///  增加一条记录
     ///   </summary>
     ///   <param name="model"></param>
     ///   <returns></returns>
     int  Add(Model.Example model);
     #endregion

} 

5、SqlServerDAL 

public   class  Example:IDAL.IExample
{
     public   int  Add(Model.Example model)
    {
         return   0 ;
    }
}

6、Model 

///   <summary>
///  Example:实体类
///   </summary>
[Serializable]
public   class  Example
{
     private   string  _id =  "" ;
     private   string  _name =  "" ;
     ///   <summary>
     ///  ID
     ///   </summary>
     public   string  ID
    {
         set  { _id = value; }
         get  {  return  _id; }
    }
     ///   <summary>
     ///  Name
     ///   </summary>
     public   string  Name
    {
         set  { _name = value; }
         get  {  return  _name; }
    }

} 

7、Web.config 

< appSettings >
   <!-- DAL反射配置 -->
   < add  key ="DALPath"  value ="SqlServerDAL"   />
</ appSettings >

转载于:https://www.cnblogs.com/sydeveloper/archive/2013/04/13/3017814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值