I have a windows service application that work with multithread. I use NHibernate in data access layer of this application.
What is your suggestion for session management in this application. I read about UNHAddins, Is it a good solution?
I have a windows service application that work with multithread. I use NHibernate in data access layer of this application.
What is your suggestion for session management in this application. I read about UNHAddins, Is it a good solution?
I use NHibernate's built in contextual sessions. You can read about them here:
http://nhibernate.info/doc/nhibernate-reference/architecture.html#architecture-current-session
Here is an example of how I use this:
In addition to this I have the following in my hibernate config file:
i've not ever looked at the unhaddins, but here's what i use for wcf stuff, should probably work for multithreaded general stuff too i imagine.
this is the session context:
this is the context manager :
Edit:
to be clear, as the other answer states, the thread static context will work out of the box. the main advantage of what i have here is 1) you get to be in control, and 2) its a lazy implementation, so you don't have to start a session for each thread if its not necessary. less connection to the db is always better, imho.