what is the best Session management opt ion for Asp.net mvc - wcf - BLL - Nhibernate repository
I have an application architecture which has following layers (or c# projects).
- web front end (asp.net mvc2)
- service laye开发者_运维技巧r (normal c# class library)
- Model layer (normal c# class library with entities, service and repository Interfaces)
- Data layer (implements repository interface defined in BLL and uses NHibernate)
ISession is opened per http request and its working fine.
Now, I would like to add wcf layer on top of my current service layer. wcf project plainly calls original service layer classes. But as soon as I do this, the session/session factory at asp.net becomes unusable/unavailable. Looks like, wcf is running in totally different context than asp.net. Hence I would like to move the logic of initinializing session factory and session management to wcf. How should I do it? and even before is it a good practice? one of the reason I would like to add wcf is because I want to expose the operations to other applications (which may not be http based).
Any help, blog post or book reference would be greatly appreciated.
Use Per-call instancing of NHibernate session. Check this article. It explains how to create attribute which will attach Session to current instance context.
you probably want to have WCF running in the same context as asp.net... try this article: http://msdn.microsoft.com/en-us/library/aa702682.aspx
精彩评论