EMROOM EMROOM为你带来创造E世界明天的资本 设为首页
加入收藏
站长信箱
首页网络编程ASP代码下载网页设计服 务 器网络安全数 据 库SEO探索业界动态IT数码IT报价网站地图
当前位置:EMROOM--用System.Web.Caching.Cache保存数据类的缓存
用System.Web.Caching.Cache保存数据类的缓存
〖双击滚屏,单击停止〗〖放大字体〗〖缩小字体
 public class DataProvider
 {
  public static IDataProvider Instance()
  {
   //use the cache because the reflection used later is expensive
   Cache cache = System.Web.HttpContext.Current.Cache;

   if ( cache["IDataProvider"] == null )
   {
    //get the assembly path and class name from web.config
    String prefix = "";
    NameValueCollection context =

(NameValueCollection)ConfigurationSettings.GetConfig("appSettings");
    if (context == null)
    {
     //can not get settings
     return null;
    }

    String assemblyPath = context[prefix +

"DataProviderAssemblyPath"];
    String className = context[prefix +

"DataProviderClassName"];

    // assemblyPath presented in virtual form, must convert to

physical path
    assemblyPath =

HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/bin/" +

assemblyPath);     

    // Uuse reflection to store the constructor of the class

that implements IWebForumDataProvider
    try
    {
     cache.Insert( "IDataProvider", Assembly.LoadFrom(

assemblyPath).GetType( className ).GetConstructor(new Type[0]), new CacheDependency(

assemblyPath ) );
    }
    catch (Exception)
    {

     // could not locate DLL file
     HttpContext.Current.Response.Write("ERROR:

Could not locate file: " + assemblyPath + " or could not locate class " +

className + " in file.");
     HttpContext.Current.Response.End();
    }
   }
   return (IDataProvider)( 

((ConstructorInfo)cache["IDataProvider"]).Invoke(null) );
  }
 }


广告位招租,联系QQ:416346708
热点文章
推荐文章
放大字体〗〖缩小字体〗 〖关闭窗口 来源:web,发布于:EMROOM ,已被阅读:
搜索更多相关:
GOOGLE:用System.Web.Caching.Cache保存数据类的缓存
BAIDU:用System.Web.Caching.Cache保存数据类的缓存
 
文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。
如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
编辑EMAIL:emroom@126.com,谢谢!