zoukankan      html  css  js  c++  java
  • NHibernate Session的管理

    由于现在的项目数据访问层使用Nhibernate管理,访问页面 数据加载时候特别慢,

    原来是每次访问Session的时候 一开 一闭  很是消耗性能。

    访问自然也就慢了,查了些资料,Session可以进行Application级的管理

    具体代码:

     class SessionManager : IHttpModule
        {

            public void Init(HttpApplication context)
            {
                context.BeginRequest += new EventHandler(Application_BeginRequest);
                context.EndRequest += new EventHandler(Application_EndRequest);
            }

            public void Dispose()
            {
            }

            private void Application_BeginRequest(object sender, EventArgs e)
            {
                ManagedWebSessionContext.Bind(HttpContext.Current,    YQKC_ERP.DAL.NHibernateHelper.GetCurrentSession());//开启Session
            }

            private void Application_EndRequest(object sender, EventArgs e)
            {
                YQKC_ERP.DAL.NHibernateHelper.CloseSessionFactory();//关闭Session
            }
        }

    在web.config添加HttpModule

     <httpModules>
          <add name="SessinModel" type="YQKC_ERP.T.SessionManager" />
      </httpModules>

    如此 效率大大提高   真是爽啊!!!

  • 相关阅读:
    CS231n assignment3 Q1 Image Captioning with Vanilla RNNs
    使用tensorflow预测函数的参数值(a simple task)
    CS231n assignment2 Q5 TensorFlow on CIFAR-10
    CS231n assignment2 Q4 Convolutional Networks
    HDU 1561 The more, The Better
    HDU4003 Find Metal Mineral
    poj 1947 Rebuilding Roads
    2090 背包
    poj 2408 Apple Tree
    奔跑的xiaodao
  • 原文地址:https://www.cnblogs.com/zhangqifeng/p/1447207.html
Copyright © 2011-2022 走看看