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.
Session factory should be started at the application start indeed. You could check the best practices here.