2012-07-11 4 views
1

저는이 질문을 많은 답변과 함께 찾을 수 있음을 알고 있습니다. 그러나 나는 그 답변을 많이 시도했지만 작동하지 않았습니다.현재 컨텍스트에 바인딩 된 세션이 없습니다. NHibernate

Ninject와 함께 NHibernate를 사용 중입니다. 이 오류는 한 번의 작업 후에만 발생하며 다른 모든 작업은 정상적으로 작동합니다.

내 설정 테이블의 행과 내 nHibernate 구성을 변경하는 코드는 다음과 같습니다.

NHibernate에/Ninject에의 구성 :

 [TransactionFilter] 
     [HttpPost] 
     public void Options(string maxPersonsHeadquarters, string maxPersonsTextile, string maxPerGroupHeadquarters, string maxPerGroupTextile, string deleteWithGuide, string deleteWithConfirmedGuide, string deleteWithConfirmedGroupIndi) 
     { 
      Setting oldSetting = _settingRepo.GetList().ToList().ElementAt(0); 
      try 
      { 
       oldSetting.MaxPersonsHeadquarters = int.Parse(maxPersonsHeadquarters); 
       oldSetting.MaxPersonsPerGroupHeadquarters = int.Parse(maxPerGroupHeadquarters); 
       oldSetting.MaxPersonsTextile = int.Parse(maxPersonsTextile); 
       oldSetting.MaxPersonsPerGroupTextile = int.Parse(maxPerGroupTextile); 

       oldSetting.DeleteWithConfirmedGroup = bool.Parse(deleteWithConfirmedGroupIndi); 
       oldSetting.DeleteWithConfirmedGuide = bool.Parse(deleteWithConfirmedGuide); 
       oldSetting.DeleteWithGuide = bool.Parse(deleteWithGuide); 

       _settingRepo.Edit(oldSetting); 
      } 
      catch (Exception e) { 
       logger.Error("SettingController/Option: " + e.Message);  
      } 



     } 
,369 : 1)

class ArtexNinjectModule: NinjectModule 
{ 
    /// <summary> 
    /// For dependency injection with Ninject 
    /// </summary> 
    public override void Load() 
    { 


     this.Bind<IRepository<Guide>>().To<GuideRepository>(); 
     this.Bind<IRepository<GuideReservation>>().To<GuideReservationRepository>(); 
     this.Bind<IRepository<Alert>>().To<AlertRepository>(); 
     this.Bind<IRepository<ReceiveAlert>>().To<ReceiveAlertRepository>(); 
     this.Bind<IRepository<TourType>>().To<TourTypeRepository>(); 
     this.Bind<IRepository<Role>>().To<RoleRepository>(); 
     this.Bind<IRepository<Language>>().To<LanguageRepository>(); 
     this.Bind<IRepository<GuideLanguage>>().To<GuideLanguageRepository>(); 
     this.Bind<IRepository<Member>>().To<MemberRepository>(); 
     this.Bind<IRepository<Reservation>>().To<ReservationRepository>(); 
     this.Bind<IRepository<Groep>>().To<GroepRepository>(); 
     this.Bind<IRepository<Individual>>().To<IndividualRepository>(); 
     this.Bind<IRepository<Address>>().To<AddressRepository>(); 
     this.Bind<IRepository<BlockedDate>>().To<BlockedDateRepository>(); 
     this.Bind<IRepository<Setting>>().To<SettingRepository>(); 
     this.Bind<ISessionFactory>().ToMethod(x => NHibernateHelper.SessionFactory).InSingletonScope(); 
     this.Bind<ISession>().ToMethod(x => NHibernateHelper.SessionFactory.OpenSession()).InRequestScope(); 

    } 

} 

2)

public static class NHibernateHelper 
{ 
    private static ISessionFactory _sessionFactory; 

    public static ISessionFactory SessionFactory 
    { 
     get { return _sessionFactory ?? (_sessionFactory = CreateSessionFactory()); } 
    } 

    private static ISessionFactory CreateSessionFactory() 
    { 

     return new Configuration() 
      .Configure() 
      .AddAssembly(typeof(NHibernateHelper).Assembly) 
      .BuildSessionFactory(); 
    } 
} 

3)

public class NHHttpModule : IHttpModule 
{ 

    protected readonly ILog Logger = LogManager.GetLogger("Application"); 
    public void Init(HttpApplication context) 
    { 


     context.EndRequest += ApplicationEndRequest; context.BeginRequest += ApplicationBeginRequest; 
    }  
    public void ApplicationBeginRequest(object sender, EventArgs e) 
    { 

     if (!CurrentSessionContext.HasBind(NHibernateHelper.SessionFactory)) 
     { 
      CurrentSessionContext.Bind(NHibernateHelper.SessionFactory.OpenSession()); 
      Logger.Debug("BEGIN REQUEST"); 
     } 
    }  
    public void ApplicationEndRequest(object sender, EventArgs e) 
    { 
     Logger.Debug("END REQUEST"); 
     ISession currentSession = CurrentSessionContext.Unbind(NHibernateHelper.SessionFactory); 
     if (currentSession != null) 
     { 
      currentSession.Close(); 
      currentSession.Dispose(); 
     } 
    } 
    public void Dispose() 
    { 

    } 
} 

이 작용 인

내 문제를 해결하기에 충분한 정보가 있기를 바랍니다. 더 많은 정보가 필요하면 알려주세요. 미리 감사드립니다.

+0

나를 도와 줄 수있는 사람이 누구입니까? :/ – Sllix

+0

리포지토리의 경우 - http 모듈에서는 바인드 된 세션을 사용하지 않지만 ninject가 세션을 주입 한 것으로 보입니다. 어쩌면 http 모듈을 사용하지 않을 경우 제거 할 수 있습니다. –

+0

왜 제거 하시겠습니까? 내가 사용할 게. – Sllix

답변

1

나는 이것에 대한 답을 찾았습니다. 여러분은 답을 알 수 없기 때문에 jQuery 문제였습니다.

버튼을 클릭하면 jQuery 함수로 이동합니다. 그리고이 기능은 내 컨트롤러에 게시했습니다.

버튼 입력 유형이 '제출'되었으므로 컨트롤러에 2 개의 게시물이 있습니다.

2 개의 게시물, 1 세션 ==> '현재 세션에 연결된 세션 없음'오류가 발생합니다!

도움 주셔서 감사합니다.

관련 문제