NHibernate - Session Singleton C #

Trying to port NHibernate to an existing C # WinForms application, and I'm currently looking for a better way to manage sessions. I am only studying NHibernate, so please excuse my lack of knowledge, can someone please provide me with any session management code that we can use, most of our web application software solutions.

Any help is appreciated.

+3
source share
1 answer

Assuming you are comfortable working with XML and the NHibernate configuration itself, there is one object that you need to make a singleton, i.e. an API ISessionFactory. The reason for this is that the full configuration regarding your connection, as well as all object mappings, are loaded into memory, so NHibernate knows how and where it will be stored in the underlying data warehouse. Therefore, the API is a ISessionFactoryvery expensive instance.

As for sessions, there are two aspects to consider: whether you want a session without state or state. This choice is entirely yours, but know the difference.

API ISession . - , , , NHibernate, , , , , . , , API . , , . API ISession API ITransaction. ITransaction, , , Begin Transaction, SQL (TSQL, PL/SQL ). , , , , , . API ISession . API ISession . , API ISession, - , ISession , . API ISession , , .

API IStatelessSession , . , , . , , , . IStatelessSession API ITransaction, . . IStatelessSession , , "" . API , , -, .

, API ISession IStatelessSesion, .

+1

Source: https://habr.com/ru/post/1778320/


All Articles