标签:
public class DataCache { // 获取当前应用程序指定CacheKey的Cache值 public static object GetCache(string CacheKey) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; return objCache[CacheKey]; } // 设置当前应用程序指定CacheKey的Cache值 public static void SetCache(string CacheKey, object objObject) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; objCache.Insert(CacheKey, objObject); } }
//不使用缓存 private static object CreateObjectNoCache(string AssemblyPath, string classNamespace) { try { object objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace); return objType; } catch//(System.Exception ex) { //string str=ex.Message;// 记录错误日志 return null; } } //使用缓存 private static object CreateObject(string AssemblyPath, string classNamespace) { object objType = DataCache.GetCache(classNamespace); if (objType == null) { try { objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace); DataCache.SetCache(classNamespace, objType);// 写入缓存 } catch//(System.Exception ex) { //string str=ex.Message;// 记录错误日志 } } return objType; }
// 创建S_UserRepository数据层接口。 public static IS_UserRepository CreateS_User() { string ClassNamespace = AssemblyPath + ".S_UserRepository"; object objType = CreateObject(AssemblyPath, ClassNamespace); return (IS_UserRepository)objType; }
private readonly IS_UserRepository bllS_User = DataAccess.CreateS_User(); [WebMethod] public string HelloWorld() { int total; string strName = bllS_User.GetInfo("", 10, 1, out total).FirstOrDefault().UserName; return "Hello World: " + strName; }
……..
博客链接地址:点此跳转
Technologies
Patterns & Practices
点此查看链接地址
EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(完)
标签:
原文地址:http://www.cnblogs.com/wangweimutou/p/4723470.html