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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Even though I set ReuseScope.None, it is still not supporting parallel transactions.
Don't know anything about NHibernate parallel transactions, maybe you need a new session instead of reusing the existing one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.