This project is read-only.

Unit of work example

Topics: Web Api
Oct 28, 2011 at 12:22 AM

I am trying to get a unit of work pattern working (specifically session per request with nhibernate) but am having trouble trying to find the right extension points. 

Are there any examples around to guide me in the right direction?

I am using IQueryable using something like the below but the using statement seems to dispose too early. If I remove the using statement it works fine but obviously I need to make sure my connections are disposed properly.




public class ContactsApi   


[WebGet(UriTemplate = "")]       

public IQueryable<Contact> Get()       


using (var session = Global.SessionFactory.OpenStatelessSession())           


return session.Query<Contact>().Take(20);