If you are using StructureMap to manage sessions for NHibernate, you may have encountered situations where you would like to dispose of those sessions in a clean and efficient manner. You could create your own code to manage this (good luck with that) or you could use StructureMap to handle that too.
In the current version of StructureMap, you can use the following code placed in the Application_EndRequest event of your Global.asax file.
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
If you are using an old release of StructureMap, you can use the following code placed in the Application_EndRequest event of your Global.asax file.
HttpContextBuildPolicy.DisposeAndClearAll();
Either way, you can use StructureMap to manage the clean up of your sessions in NHibernate. I hope this knowledge makes your life easier!
Smooches,
Kila
This blog is for all Microsoft & .net lovers who may find themselves in need of help or information once in a while. We all have questions and we all need to know more than we know right now. When I come across things that I think may be useful, I post it. When I have something to say that I think is important, which is everything, I post it. All of my C#, ASP.NET, VB, AJAX & programming friends around the world are welcome to the info in my blog - Ramblings Of A Crazy DotNet Woman!
Subscribe to:
Post Comments (Atom)
2 comments:
Good tip :)
I am using this code, however, disposing of the session this way does not seem to flush the session. So, I'm left with flushing it explicitly (or using a transaction and committing).
Am I missing something?
Post a Comment