The first thing I can offer is to make both instances of ISessionFactory static. These must be singleton because they are very expensive to create instances.
EDIT NO. 1
Would you recommend I create sessions when I need them, or leave them open?
The ISession API handles the internal connection. After some time, if interaction with the database is not requested, the connection is closed, although your ISession stores its connection instance. After he needs to perform some other transactions with the database, he then reopens the previously used connection.
To answer your question, the preferred approach is to instantiate the ISession API on the page (on the Internet) or in the form (on the desktop). For example, suppose you have accounting software and the user has some control for customers. Then, when your CustomerMgmtForm loads, you must provide an ISession instance ISession that it can load your customers, track your changes, deletions, and new customers created (after joining ISession , so that when you call SaveOrUpdate() , ISession knows what it should do with trackable changes and transitional objects.
Why do I need one copy per page or form?
Since the ISession API tracks all changes that occur to an object, imagine once you have downloaded your customers, suppliers, and some other objects that you need to take care of in your application. Each of the changes made to customers is not entitled to suppliers. But these clients will still be there, because it is an instance of ISession that you used for your clients! Then your requirements for memory applications grow with the number of loaded objects. In addition, it is known that when ISession becomes too large in memory, this can lead to some memory leaks and then consider NHamernate to be a more invalid session, discarding all your unsaved changes and everything like the session that was tracking your objects is now invalid.
In addition to this, when you open let, say CustomerMgmtForm, you will have to manage Customer objects. You are more likely to not follow your customers after you close the form, or even open SuppliersMgmtForm, in which you will manage your suppliers. Thus, you will have two instances of the ISession API: the first is customerMgmtSession , the other is suppliersMgmtSession . Thus, they should never grow too large to cause a memory leak, as they both have their own entities to process or leave. Both are completely independent of each other.
Following this approach, you must close and remove the ISession API instance for the FormClosing event for Windows Forms or any other equivalent on the Web. So, now in the Windows service, you need to decide what is the ideal situation and decide where it will be most suitable for your needs, depending on what your service does.
However, if your service does not require tracking your changes or any actions on your objects, the IStatelessSession API may be more suitable for use. Using this, I am sure that you open or create an instance of a stateless session only when you need to interact with the base database, since IStatelessSession does not need to use it because it does not provide resources to track changes made to your objects. This is the main and actually only, if I remember correctly, the difference between the ISession API and IStatelessSession .
EDIT No. 2
Doing this as mentioned in my EDITION # 1 above can also help you solve your problem since you will never need to call ISessionFactory.GetCurrentSession() .
Hope this helps! =)