Unit of work example

Topics: Web Api
Oct 27, 2011 at 11:22 PM

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.

Thanks,

Nabil

 [ServiceContract]   

public class ContactsApi   

{       

[WebGet(UriTemplate = "")]       

public IQueryable<Contact> Get()       

{           

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

{               

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

}       

}   

}