Hi Folks,
I'm new to NHibernate. I've created a vs solution with a couple of c# 3.5 class library projects to test the NHibernate waters. One of my c# projects is a collection of NUnit tests to test out my domain, repositories, etc. In NUnit project I have a app.config with the NHibernate configuration info. When I try to get an ISession using GetSessionFactory().GetCurrentSession() I get the following error:
No CurrentSessionContext configured (set the property current_session_context_class)!
The strange thing is that the proeprty is set. I'm using:
<property name="current_session_context_class">Web</property>
I've looked everywhere on the net but can't find an answer. The only thing I could think of is that 'Web' may not work if I'm using a class library. Don't know. Here's my session factory class if that would help:
Code:
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
namespace Infrastructure.Repository
{
public class SessionFactory
{
private static ISessionFactory _SessionFactory;
private static void Init()
{
var config = new Configuration();
config.AddAssembly("Infrastructure.Repository");
log4net.Config.XmlConfigurator.Configure();
config.Configure();
_SessionFactory = config.BuildSessionFactory();
}
public static ISessionFactory GetSessionFactory()
{
if (_SessionFactory == null)
{
Init();
}
return _SessionFactory;
}
public static ISession GetNewSession()
{
return GetSessionFactory().OpenSession();
}
public static ISession GetCurrentSession()
{
return GetSessionFactory().GetCurrentSession();
}
}
}