在前面的基础上加个工厂
接口层IDAL
using System;
using System.Collections.Generic;
using System.Text;
namespace IDAL
{
public interface AnimalsIDAL
{
bool Add(Model.Animals a);
}
}
工厂层:Factory
缓存帮助类
Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Caching;
using System.Web;
using System.Reflection;
using System.Configuration;
namespace Factory
{
public class CachHelper
{
static string dal = ConfigurationManager.AppSettings["DAL"];
static object GetCach(string key)
{
return HttpRuntime.Cache[key];
}
static void InsertCach(string key, object value)
{
Cache cach = HttpRuntime.Cache;
cach.Insert(key, value);
}
public static object CareteInstance(string classname)
{
object obj = GetCach(classname);
if (obj == null)
{
obj = Assembly.Load(dal).CreateInstance(dal + "." + classname);
InsertCach(classname, obj);
}
return obj;
}
}
}
Code
using System;
using System.Collections.Generic;
using System.Text;
using IDAL;
namespace Factory
{
public class DALFactory
{
public static IDAL.AnimalsIDAL CareateAnimalIDAL()
{
return (AnimalsIDAL)CachHelper.CareteInstance("AnimalsDAL"); ;
}
}
}
BLL:
Code
using System;
using System.Collections.Generic;
using System.Text;
namespace BLL
{
public class AnimalsBLL
{
public bool Add(Model.Animals animal)
{
return Factory.DALFactory.CareateAnimalIDAL().Add(animal);
}
}
}