简体   繁体   English

WCF + NHibernate + ISession =?

[英]WCF + NHibernate + ISession =?

I'm a beginner concerning both WCF and NHibernate. 我是WCF和NHibernate的初学者。 However, I have to do a little project involving several services (made with WCF) and a persistent layer (made with NHibernate). 但是,我必须做一个涉及多个服务(使用WCF制作)和持久层(使用NHibernate制作)的小项目。

My problem concerns the usage of ISession and ISessionFactory. 我的问题涉及ISession和ISessionFactory的使用。 I have read (and seen) that the instantiation of ISessionFactory is very heavy (and thread-safe). 我已阅读(并看到)ISessionFactory的实例化非常繁重(并且是线程安全的)。 So, I think that I could instantiate this class only once during the application runtime. 所以,我认为我可以在应用程序运行时期间只对该类进行一次实例化。 I'm right? 我是正确的?

My problem concerns more the ISession class. 我的问题更多地涉及ISession类。 I don't exactly know at which granularity I have to use it. 我不确切知道我必须使用它的粒度。 I think that I should use/create one instance for each call to service operation (I use "per-call services"). 我认为我应该为每次调用服务操作使用/创建一个实例(我使用“per-call services”)。 Again, I'm right? 再一次,我是对的?

You're spot on. 你是现货。 The session factory is expensive to construct and well suited as singleton while the session is a more lightweight contextual object wrapping the "unit of work". 会话工厂的构造成本很高,非常适合作为单例,而会话是一个包含“工作单元”的更轻量级的上下文对象。

To learn more you could read about the castle WCF facility that proposes a solution to this problem. 要了解更多信息,您可以阅读有关提出此问题解决方案的城堡WCF设施。 Here's a blog post that explores it. 这是一篇探索它的博客文章

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

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