How to handle ASP.NET MVC asynchronous requests

Skip to first unread message

Michael Powell

May 18, 2016, 7:08:41 PM5/18/16

I've been putting this question off for a little while now, but I am
crossing a threshold in the application that I need to address it.

I have several asynchronous requests pouring in from a client side
that may require separate SQL requests, and I need to coordinate an
ISession being built and/or restored, i.e. if I should coordinate
building the configuration with already-built Hbm files, for instance.

I am coordinating these through an Autofac Dependency Injection, but I
suspect I have my lifetimes incorrect, because I am getting exceptions
dealing with the Hbm files. At minimum, I need to coordinate the core
configuration/factories/repositories with the requests, get their
lifetime(s) correct across the controller(s)/session(s)/etc.

What I am looking for here is general guidance. If someone has seen
this before, I can't imagine it's that uncommon for high performance,
responsive web sites, ASP.NET, MVC, etc.

Eventually, I suspect I should be able to do something like this on
the client side (JavaScript/jQuery):

$.when(ajax1(), ajax2(), ..., ajaxn()).done(response1, response2, ...,

Any suggestions, pointers, thanks in advance!


Michael Powell

Gleb Chermennov

Aug 11, 2016, 6:38:21 AM8/11/16
to Fluent NHibernate
What kind of exceptions are you getting? What does it say?
I'm not familiar with Autofac, but according to NHibernate docs, ISession is NOT thread-safe - so you should modify your lifecycle accordingly, I suppose.

четверг, 19 мая 2016 г., 2:08:41 UTC+3 пользователь mwpowellhtx написал:

Fran Knebels

Aug 11, 2016, 7:42:18 AM8/11/16

What does you session strategy look like now?

I've taken the approach of creating a new session at Application_BeginRequest and storing it in the HttpContext.  So it's a session per request. 

I inject my session into a generic Repository and the repositories into my controllers using windsor and don't see any threading issues.

You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit
Reply all
Reply to author
0 new messages