I've written the following code:

        public class DataConfiguration : IDataConfiguration
        {
                private readonly ISessionFactory sessionFactory;

                public DataConfiguration(ISessionFactory sessionFactory)
                {
                        this.sessionFactory = sessionFactory;
                }

                public void OpenSession()
                {
                        ISession session = sessionFactory.OpenSession();
                        CurrentSessionContext.Bind(session);
                }

                public void CloseSession()
                {
                        ISession session = 
CurrentSessionContext.Unbind(sessionFactory);
                        session.Flush();
                        session.Dispose();
                }
        }

and I'm using StructureMap to inject the appropriate
CurrentSessionContext (WebSessionContext) for my web app which works
flawlessly.  Currently for my integration tests (using NUnit), I'm
injecting ThreadStaticSessionContext though I think
ThreadLocalSessionContext would be more appropriate.  Unfortunately,
ThreadLocalSessionContext only extends ICurrentSessionContext and not
CurrentSessionContext.  When running the entire integration test
suite, I get consistent failures on certain tests because the ISession
is closed:

SetUp : System.ObjectDisposedException : Session is closed!
Object name: 'ISession'.

However, if I run the failing tests in isolation, they work every
time.

Is there a better way to manage my session for my integration tests?

-- 
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.

Reply via email to