1

I am getting the session by injecting session to service method in global.asax as

1

protected void Application_Start()
{    
  this.RegisterContainer(); 
}

2

private void RegisterContainer()
{
    container.Register<IActivityService>(c => new  ActivityService(SessionFactory.GetCurrentSession()));
}

3 In service method i am getting the session as

using (var transaction = _session.BeginTransaction())
{
    ........................        
}

the problem is when concurrent requests came to this service method, it is throwing exceptions.I came to know that Nhibernate is not supporting concurency.Ho to achieve it using Funq Container?

Mert
  • 6,432
  • 6
  • 32
  • 68
Raghu
  • 11
  • 5

1 Answers1

1

By default ServiceStack's IOC registers dependencies as a singleton by default whereas you should register a transient dependency for this instead with:

container.Register<IActivityService>(c => 
    new ActivityService(SessionFactory.GetCurrentSession()))
.ReusedWithin(ReuseScope.None);

Also this previous question shows other registration examples using NHibernate with ServiceStack.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Even though I set ReuseScope.None, it is still not supporting parallel transactions. – Raghu Jul 12 '16 at 17:18
  • Don't know anything about NHibernate parallel transactions, maybe you need a new session instead of reusing the existing one? – mythz Jul 12 '16 at 17:34