Chapter 4 Architecture Overview
A very high-level overview of the nhibana architecture:
This figure shows that nhib.pdf uses database and configuration file data to provide persistence services (and persistent objects) for applications ).
We tried to show more details about the NHibernate runtime architecture. But unfortunately, nhib.pdf is flexible and provides several different running methods. Let's take a look at two extreme situations. In a lightweight system, applications provide their own ADO. NET connections and manage transactions. This method uses a minimum subset of the nhib.pdf API.
In a comprehensive solution system, all underlying ADO. NET APIs are abstracted for applications, and NHibernate takes care of all the details for you.
The following are some object definitions in the figure:
-
SessionFactory (
NHibernate.ISessionFactory)
-
A thread-safe and immutable cache snapshot for compiled ing files of a single database. It isSessionIsConnectionProvider. You can hold an optional (second-level) data cache and store data that can be reused in transactions at the process or cluster level.
-
Session, Session (
NHibernate.ISession)
-
A single thread, short-lived object, represents a conversation between the application and the persistence layer. Encapsulates An ADO. NET connection. YesTransaction. Save the cache of the required (level 1) Persistent object, which is used to traverse the object graph or find the object through the identifier.
-
Persistent and Its Collections)
-
Objects of a single thread with short life cycle, including persistence and commercial functions. They may be common objects, and the only thing special is that they now belong to and only belong to oneSession. OnceSessionAre disabled, they will allSessionCan be used freely at any program layer (for example, directly as a DTO or data transmission object transmitted to the presentation layer ).
-
Temporary Object and its Collection)
-
CurrentlySession. They may have just been instantiated by the program, but they haven't been made persistent yet, or they may have been turned off by a closedSessionInstantiated.
-
Transaction (
NHibernate.ITransaction)
-
(Optional) Single-threaded, short-lived object. The application uses it to represent atomic operations of a batch of jobs. Is the abstraction of the underlying ADO. NET transaction. A Session may span multipleTransactionTransaction.
-
ConnectionProvider (
NHibernate.Connection.ConnectionProvider)
-
(Optional) Factory connected by ADO. NET. From the underlyingIDbConnectionAbstract. Invisible to applications, but can be extended/Implemented by developers.
-
TransactionFactory (
net.sf.hibernate.TransactionFactory)
-
(Optional) the factory of the transaction instance. Invisible to applications, but can be extended/Implemented by developers.
In the light structure above, the program is not usedTransaction/TransactionFactoryOrConnectionProviderAPI, directly talking to ADO. NET.