to expand on Francisco statement. session factory should be a
singleton within your application. it should be built on application
startup.
Application_Start for asp.net Progam.Main for console and win apps.
ServiceBase.OnStart for windows services, etc.

there is also the issue of managing the scope of session. if you open/
close a session for each query you are not benefiting from the
features provided by the ISession implementation. for web apps most
applications open a session on the begin request and dispose on end
request. for desktop and windows services the concept of session per
business conversation is used. I have also used thread static static
session scopes when working with message buses (rhino, nservice, mass
transit)
with NH operations should always occur within a transaction read and
writes. there are features within NH that occur only when a
transaction is present.

On Sep 24, 7:46 am, "Francisco A. Lozano" <[email protected]> wrote:
> You should only build the SessionFactory once.
>
> Francisco A. Lozano
>
> On Thu, Sep 24, 2009 at 13:44, shapovalov <[email protected]> wrote:
>
> > Hello,
>
> > now for every method to read or write in database I create new session
> > this way
> >                ISessionFactory sessionFactory =
> > config.BuildSessionFactory();
> >                ISession session = sessionFactory.OpenSession();
>
> > What about performance? I read about solution while session is opened
> > in BeginRequest and closed in EndRequest. Is it much more quickly?
> > What is the best practice of using ISession?
> > Where and how have I close connection?
> > Now every method looks like
> > using (ISession session = GetSession())
> > {
> > }
>
> > Thanks,
> > Alexander.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to