ServiceStack NHibernate Session per request

后端 未结 3 573
名媛妹妹
名媛妹妹 2021-01-12 05:01

I am starting to build an app, and I\'m planning to use ServiceStack. Just want to know what are the best practices/good approaches for handling NHibernate ISession or, othe

3条回答
  •  借酒劲吻你
    2021-01-12 05:58

    Creating a session per request using a HttpHandler is the most common way of doing it that I have found. Ayende has explained that creating a session is really light weight. http://ayende.com/blog/4123/what-is-the-cost-of-opening-a-session

    Ayende actually has series of posts where in he gradually builds out the data access solution. Each post explains why he did what he did and what issues need to be resolved with the steps taken so far. Start here: http://ayende.com/blog/4803/refactoring-toward-frictionless-odorless-code-the-baseline

    Finally, http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx

    All of the above are variations of session per request. The common thing across all is not having to manually worry about creating a session/transaction. They will commit/rollback the transactions automatically.

提交回复
热议问题