concept SessionFactory in category .net

This is an excerpt from Manning's book NHibernate in Action.
The ISessionFactory certainly isn’t lightweight! It’s intended to be shared among many application threads. There is typically a single instance of ISessionFactory for the whole application—created during application initialization, for example. But if your application accesses multiple databases using NHibernate, you’ll need a SessionFactory for each database.
The SessionFactory caches generated SQL statements and other mapping metadata that NHibernate uses at runtime. It can also hold cached data that has been read in one unit of work and which may be reused in a future unit of work or session. This is possible if you configure class and collection mappings to use the second-level cache.
To create an ISessionFactory instance, you first create a single instance of Configuration during application initialization and use it to set the database access and mapping information. Once configured, the Configuration instance is used to create the SessionFactory. After the SessionFactory is created, you can discard the Configuration class.
Listing 10.1. A simple NHibernate helper class
public class NHibernateHelper { public static readonly ISessionFactory SessionFactory; static NHibernateHelper() { try { Configuration cfg = new Configuration(); SessionFactory = cfg.Configure().BuildSessionFactory(); } catch (Exception ex) { Console.Error.WriteLine(ex); throw new Exception("NHibernate initialization failed", ex); } } public static ISession OpenSession() { return SessionFactory.OpenSession(); } }