Hey all,
I'm getting the following exception when I call
factory.GetCurrentSession() from my unit test class constructor:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=NHibernate
StackTrace:
at NHibernate.Context.WebSessionContext.GetMap() in d:\Builds
\NHibernate\nhibernate\src\NHibernate\Context
\WebSessionContext.cs:line 24
at NHibernate.Context.MapBasedSessionContext.get_Session() in d:
\Builds\NHibernate\nhibernate\src\NHibernate\Context
\MapBasedSessionContext.cs:line 23
at NHibernate.Context.CurrentSessionContext.CurrentSession() in
d:\Builds\NHibernate\nhibernate\src\NHibernate\Context
\CurrentSessionContext.cs:line 33
at NHibernate.Impl.SessionFactoryImpl.GetCurrentSession() in d:
\Builds\NHibernate\nhibernate\src\NHibernate\Impl
\SessionFactoryImpl.cs:line 997
at
RentBase.Domain.NHibernateRegistry.GetCurrentNHibernateSession(IContext
context) in C:\inetpub\wwwroot\RentBase\RentBase.Domain
\NHibernateRegistry.cs:line 42
at RentBase.Domain.NHibernateRegistry.<.ctor>b__0(IContext
context) in C:\inetpub\wwwroot\RentBase\RentBase.Domain
\NHibernateRegistry.cs:line 26
at StructureMap.Pipeline.LambdaInstance`1.build(Type
pluginType, BuildSession session)
InnerException:
This is the code I use to store the session:
public class MyTestBase : IDisposable
{
public MyTestBase()
{
ObjectFactory.Initialize(x =>x.AddRegistry(new
NHibernateRegistry()));
var factory = ObjectFactory.GetInstance<ISessionFactory>();
var session = factory.OpenSession();
ThreadLocalSessionContext.Bind(session);
}
public void Dispose()
{
var factory = ObjectFactory.GetInstance<ISessionFactory>();
ThreadLocalSessionContext.Unbind(factory).Dispose();
}
}
Then my test that throws the exception looks like:
[Test]
public void NHGoBoom()
{
var session =
ObjectFactory.GetInstance<ISessionFactory>().GetCurrentSession();
...
}
I'm using NHibernate 3.0.0.4967 with StructureMap. I don't think that
StructureMap is causing the troubles, but I could be wrong.
StructureMap stores the ISession object on the local thread (I
use .HybridHttpOrThreadLocalScoped() to do so). Other than storing
the session in ThreadLocalSessionContext in my base class constructor,
do I have to explicitly tell NH not to look for HttpContext by some
other means?
Thanks for your help,
Jim
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.