tags:

views:

1916

answers:

1

Hi,

I'm a beginner concerning both WCF and NHibernate. However, I have to do a little project involving several services (made with WCF) and a persistent layer (made with NHibernate).

My problem concerns the usage of ISession and ISessionFactory. I have read (and seen) that the instantiation of ISessionFactory is very heavy (and thread-safe). 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. 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"). Again, I'm right?

+3  A: 

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. Here's a blog post that explores it.

Cristian Libardo