Asp.net mvc - wcf - BLL - Nhibernate 存储库的最佳会话管理选项是什么
我有一个应用程序架构,它具有以下层(或 C# 项目)。
- Web 前端 (asp.net mvc2)
- 服务层(普通 C# 类库)
- 模型层(带有实体、服务和存储库接口的普通 C# 类库)
- 数据层(实现 BLL 中定义的存储库接口并使用 NHibernate)
每个 http 打开 ISession请求及其工作正常。
现在,我想在当前的服务层之上添加 wcf 层。 wcf项目明文调用原来的服务层类。但一旦我这样做,asp.net 上的会话/会话工厂就变得不可用/不可用。看起来,wcf 运行在与 asp.net 完全不同的上下文中。因此我想将初始化会话工厂和会话管理的逻辑移至wcf。我该怎么做呢?甚至在此之前这是一个好的做法吗?我想添加 wcf 的原因之一是因为我想将操作公开给其他应用程序(可能不是基于 http 的)。
任何帮助、博客文章或书籍参考将不胜感激。
I have an application architecture which has following layers (or c# projects).
- web front end (asp.net mvc2)
- service layer (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 NHibernate 会话的每次调用实例化。查看这篇文章。它解释了如何创建将会话附加到当前实例上下文的属性。
Use Per-call instancing of NHibernate session. Check this article. It explains how to create attribute which will attach Session to current instance context.
您可能希望 WCF 在与 asp.net 相同的上下文中运行...尝试这篇文章:
http://msdn.microsoft.com/en-us/library/aa702682.aspx
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