/// <summary> /// Web Application의 요청 처리 후 사후 처리를 한다. (실제 처리하는 것은 없고, 재정의가 가능하도록 남겨두었다.) /// </summary> public virtual void OnEndRequest(object sender, EventArgs e) { if (IsDebugEnabled) { log.Debug("사용자 요청을 모두 처리하고, UnitOfWork에 대해 종료처리를 시작합니다."); } lock (_syncLock) { // no error in asp.net pages and long conversion mode in Unit Of Work. // if (HttpContext.Current.Server.GetLastError() == null && UnitOfWork.InLongConversation) { if (IsDebugEnabled) { log.Debug("Disconnect current NHibernate session. not close, just disconnect!!!."); } UnitOfWork.CurrentSession.Disconnect(); if (IsAspSessionAvailable == false) { throw new InvalidOperationException( "HttpSession must be enabled when using Long Conversation in Unit Of Work pattern!!! " + "If you are using web services, make sure use [WebMethod(EnabledSession=true)]"); } LongConversationManager.SaveConversation(); } else { if (IsDebugEnabled) { log.Debug("if not in long conversation mode. current unit of work instance is disposing."); } if (UnitOfWork.IsStarted) { UnitOfWork.Stop(); if (IsDebugEnabled) { log.Debug("UnitOfWork를 끝냈습니다!!!"); } } } } if (IsDebugEnabled) { log.Debug("사용자 요청을 모두 처리하고, UnitOfWork에 대해 종료처리를 완료했습니다."); } }
/// <summary> /// ASP.NET에서 페이지 또는 XML Web services 같은 이벤트 처리기의 실행을 시작하기 바로 전에 발생하는 Event에 대한 Handler<br/> /// 1. Application 생성 시 한번만 IoC 관련 정보를 초기화 합니다.<br/> /// 2. UnitOfWork를 Start 시킵니다. /// </summary> /// <remarks> /// 기본 설정 파일이 아닌 다른 파일에 대해 초기화를 하려면 재정의를 해야 한다. /// </remarks> protected override void OnBeginRequest(object sender, EventArgs e) { base.OnBeginRequest(sender, e); if (NeedStartUnitOfWork() == false) { if (HttpContext.Current != null) { if (IsDebugEnabled) { log.Debug("Unit of Work를 시작할 필요가 없는 단순 파일 요청이므로, UnitOfWork를 시작하지 않습니다!!! RawUrl=[{0}]", HttpContext.Current.Request.RawUrl); } } return; } //lock(_syncLock) { bool loadedConversation = false; // Session이 사용 가능하다면, 저장된 IUnitOfWork 객체가 있는지 확인한다. if (IsAspSessionAvailable) { if (IsDebugEnabled) { log.Debug("ASP.NET Session is available. Retrieve instance of IUnitOfWork from ASP.NET Session."); } loadedConversation = LongConversationManager.LoadConversation(); } if (loadedConversation == false) { if (UnitOfWork.IsNotStarted) { UnitOfWork.Start(); if (IsDebugEnabled) { log.Debug("UnitOfWork를 시작했습니다!!!"); } } } } }