tags:

views:

55

answers:

2

on the web application, I am using a NHibernate helper that looks up the session that was opened in a httpmodule (and committed there also).

  <property name="current_session_context_class">web</property>

In the console application, what do I do?

+1  A: 

Your options are: "call" & "thread_static". Have a look at this for more detailed explanation on all available contexts:

http://nhforge.org/wikis/reference2-0en/context-sessions.aspx

In order to have your library work for both a web and a console application you have two options:

  1. Based on a application setting in the App.config and in the web.config have the Session Factory built accordingly by setting the current_session_context_class property manually in the code and remove it from the hibernate.cfg.xml file.
  2. Include a in the web application's web.config and in the app.config of the console application. This way you can have the current_session_context_class property set to different values. If I am not mistaken the in the web.config and in the app.config overrides the values of the hibernate.cfg.xml. If I am wrong then you will just have to include in the web.config and the app.config the complete and remove the hibernate.cfg.xml file from your library.
tolism7
A: 

I found tolism7's answer useful: I have a website with

<property name="current_session_context_class">web</property>

in the hibernate.cfg.xml file referenced by web.config. I have unit tests pointing at an identical hibernate.cfg.xml file and the tests wouldn't work, but then I changed it to

<property name="current_session_context_class">thread_static</property>

in the unit test's config file and now the tests work.

CarllDev