February 2009 Entries
In my previous post, I talk about how the problem with sessions and NHibernate (NH) can get pretty tricky to deal with; specially within ASP.NET web applications. This post shows how you can use a pretty nice feature within NH that simplifies this problem. A Solution NH supports a mechanism of providing a ‘current’ session via the ISessionFactory.GetCurrentSession method by using a concept called Contextual Sessions. This is what the NH documentation says about the feature: Most applications using NHibernate need some form of "contextual" sessions, where a given session is in...
As with any piece of software development, there is more than a million ways to skin a cat. Working with NHibernate in a multi-threaded environment is no different. :) To help with the illustration of the interaction of NHibernate and ASP.NET, I’ve created a sample application out on Google code. Please feel free to check it out and run it locally. The only requirement for the sample is to have a local install of SQL Server Express. The Problem Those of you using NHibernate in a multi-threaded environment (say ASP.NET) have probably written code to maintains an ISession...