NHibernate Session-Per-Method-Call via StructureMap Nested Containers

added by Matt_TCF
12/6/2011 10:28:33 AM

4 Kicks, 169 Views

There are several documented approaches you can follow to implement the session-per-method-call pattern with NHibernate and StructureMap. The majority of these approaches fail to leverage the full capabilities of StrurctureMap and are therefore more complex than they need to be. In this short post, I’ll show you how you can implement a simpler solution by utilizing StructureMap’s nested containers.


12/6/2011 10:29:28 AM
This is a pretty sweet solution, have you considered coming up with a way to package this as a sort of contrib project to NH? The ability to drop something like this into a project via Nuget is just too tantalizing.

12/6/2011 8:57:25 PM
I hadn't thought about that, but now that you mention it, this would be something that could be packaged up fairly easily. I'd have to do a bit of digging about how to hook the behavior in using a NuGet package, but I know it's doable.