Erik van Brakel
Erik van Brakel

Reputation: 23820

Caching the sessionfactory

As far as I've gathered (read: measured), building the configuration and the sessionfactory by far takes the most time in executing a query using nhibernate. Is there anything against making the sessionfactory static, so it will only be configured once per appDomain?

I know there are locking and racing issues when using this approach, but personally I don't see where this would break my application when using this approach on the sessionfactory.

The reason I am asking this is because it's really hard to test for possible threading issues, as it doesn't occur all the time.

Upvotes: 3

Views: 867

Answers (1)

Petr Macek
Petr Macek

Reputation: 1473

Session factory should be started at the application start indeed. You could check the best practices here.

Upvotes: 5

Related Questions