We have our first NHibernate project going well. However, I still do not understand the full picture of how to manage sessions and objects in our scenario.
So, we are setting up the system structure in a permanent object model stored in a database with NHibernate.
The system consists of physical devices that the application monitors during maintenance. Therefore, when starting the service, we create device objects in the service and update their status in accordance with the data read from the device interface. The object model is maintained throughout the life of the service.
The service also serves Silverlight clients that display object data and can also manage some objects. But they must access the same objects that the service uses for monitoring, for example, because the objects also have data in memory and are not saved. (Yes, we use DTO objects to actually transfer data to clients.)
Because the service is a multi-threaded system, the question is how to manage NHibernate sessions.
Now I am considering an approach in which we only have a background thread that takes care of saving the object in the background, and other threads just put “SaveRequests” in our repository instead of directly accessing NHibernate sessions. That way, I can use one session for the service and manage the NHibernate level completely separate from the service and the clients that access the objects.
I did not find any documentation for such an installation, since everyone offers a session model per request or some options. But if I get it right, if I create an instance of the object in one session and save it in another, this is not the same object - and it also seems that NHibernate will create a new record in the database.
IOC , , , .
?