Instantiating the Confguration is very time consuming so this should the configuration should be build and reused.
Now, the approach, as far as I consider is:
- instantiate configuration and session factory just once ( first time is needed or when the application starts)
- keep it somewhere so that it can be reused ( singleton, IOC, application )
- create an ISession for every:
- request - easier to implement, gets harder on complex logic with long business flows
- business flow (one or more pages in a user session share an ISession object) - the main problem IMHO is recovering from exceptions.
- anytime an "atomic" operation, independent of anything else occurs (logging in my opinion is standalone op)
|