In the GetConfiguration
method in your SessionBuilder
, instead of the
public Configuration GetConfiguration()
{
var configuration = new Configuration();
configuration.Configure();
return configuration;
}
shown in the page you linked, simply do something like this:
public Configuration GetConfiguration()
{
return Fluently.Configure()
.Database(/* your database settings */)
.Mappings(/* your mappings */)
.ExposeConfiguration(/* alter Configuration */) // optional
.BuildConfiguration();
}
Regarding the further inquiry about handling contexts, you'd have two classes inheriting ISessionBuilder
, e.g. AspSessionBuilder
and WinAppSessionBuilder
, and inject the appropriate one for the current project. You should use the strategy outlined by Jamie Ide also posted as an answer to this question to handle contexts instead of using HttpContext
. You just simply have to modify this line:
.ExposeConfiguration(x => x.SetProperty("current_session_context_class", "web")
to something like "call"
or "thread_static"
. See this page at the NHibernate Forge wiki for a good explanation of the different contextual session types:
Contextual Sessions @ NHibernate Forge