Timmy February 2016

How to configure NHibernate with SignalR

I want to configure NHibernate only once and reuse the session factory to open different sessions to manipulate database, however the hubs are considered as transient objects and loose object state when client is initializing another request to the hub. The only way so far that i have read about is to make the objects static in order to reuse it.

Is there some other way of achieving this without making the objects static ?

myConfiguration = new Configuration();
            myConfiguration.Configure();
            mySessionFactory = myConfiguration.BuildSessionFactory();
            mySession = mySessionFactory.OpenSession();

Thank you in advance :)

Answers


Dmitry S. February 2016

There is nothing wrong with having Configuration and SessionFactory objects stored in static fields. Sessions should not be shared.

An alternative would be to use a DI container and register them as singletons.

Post Status

Asked in February 2016
Viewed 1,894 times
Voted 8
Answered 1 times

Search




Leave an answer