I am starting to build an app, and I'm planning to use ServiceStack. Just want to know what are the best practices/good approaches for handling NHibernate ISession or, other "per request" context specific session objects.
I thought registering a ISessionFactory in the Ioc like:
container.Register<ISessionFactory>(sessionFactory);
And when needed get a new Session object... Or maybe provide the session object directly:
container.Register<ISession>(c => sessionFactory.OpenSession()).ReusedWithin(ReuseScope.None);
Or either handle the ISession and a default transaction via the Global.asax BeginRequest event:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var session = factory.OpenSession();
ITransaction itrans = session.BeginTransaction();
Context.Items.Add("session", session);
Context.Items.Add("trans", itrans);
}
So, I am kind of lost, what are the best practices, given the above technologies, or similar ones, like EF or another Rest-Services framework?
Thanks in advance