简体   繁体   English

WCF 服务 + NHibernate:如何处理 session?

[英]WCF service + NHibernate: how to handle the session?

I am writing a wcf service and i wanna use NHibernate for the data access objects.我正在编写 wcf 服务,我想将 NHibernate 用于数据访问对象。 My doubt is about how would be the best approach to handle the nh's sessions.我的疑问是如何处理 nh 会议的最佳方法。

I've been reading about the topic and seems like per call is the best way, also i found the uNhAddIns implementation, but does anyone know if this is a better choice?我一直在阅读有关该主题的内容,似乎每次通话是最好的方法,我还找到了uNhAddIns实现,但是有人知道这是否是更好的选择吗?

any advice will be appreciated.任何建议将被认真考虑。

Have one NHibernateSessionFactory class such that we always get a single instance of the NHibernate session factory and start using them in wcf service on need basis. Have one NHibernateSessionFactory class such that we always get a single instance of the NHibernate session factory and start using them in wcf service on need basis. You can have a instance of this in the class implementing the operation contracts您可以在执行操作合同的 class 中拥有此实例

private readonly NHibernateSessionFactory m_sessionfactory = new NHibernateSessionFactory();

you can start using it on need basis with in the class:您可以在 class 中根据需要开始使用它:

using (ISession session = m_sessionfactory.Instance().OpenSession())
{
//----------Do something here
}

I am not sure whether you are looking for these type of details or not.我不确定您是否正在寻找这些类型的详细信息。 If not please ingnore my response.如果不是请忽略我的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM