I am creating a solution in ASP.NET MVC 2, NHibernate and DDD. I am using a semi CQRS type Model.
ASP.NET Controller send validated messaged to Service Layer which updates state of an Domain object. I have my Domain Dispatch "Events" and these are then caught by "Event Handlers" who act on them. Each of these Event Handler have access to Repository Layer and can commit an Domain Object State.
Event Handlers also insert records directly into reporting based tables using a (non NHibernate ) Repository. Event Handlers may also do non database related operations like sending emails.
Event Handler can also change state of an object thereby creating new set of events.
How can I assure that all database operation that occur during a single asp.net Request are inside a single Transaction. I have been reading some blogs ( like Kevin Williams , Matt Wrock and Davy Brion) and have got information on how to start a Session object in Begin and End Request ( Again I will be using Structure Map here) but not sure how the transaction is maintained. This was compounded by the fact that start and end Requests may be called on different threads.
My Repository Class takes NHibernate ISession in its Parameter. If I create ISession as Hybrid Scope ( StructureMap) will that ensure that during a request ISession parameter that is passed by StructrueMap remain same.
Please advise and also let me know if my question is not clear.