0
votes

I have a problem. I've setup ma session management as per wcf call. I am using StructureMap as IoC and I am injecting the session to the repository constructor.

there is one scenario when I am getting Session is closed exception. So I debug and this is the workflow: 1. SessionFactory.OpenSession() 2. Save Session in context 3. StructureMap gets the session from context (For().Use<_sessionFactory.GetCurrentSession()), and inject the session into my repository (at this moment Session.IsOpen == true) 4. I am doing some query. 5. On query execute (the exception Session Is closed is thrown) 6. WchCall ends 7. The Detach(InstanceContext) from NHibernateContextManager:IExtension is called (at this momment Session.IsOpen == true!!!!) 8. Session.Close is called

This exception happens only in one scenario, everything else is working ok.

Please help.

1
And this happens only in one class, the same repository works in another one. - Luka
And this only happens if I let StructureMap instantiate the class, but if I uset ObjectFactory.GetInstance<T>() then it works ok. - Luka

1 Answers

0
votes

Ok, found the problem. The problem was in StructureMap conviguration for this class: I had: ForSingletonOf().Use();

Now changed to: For().Use();