IDisposable support for Resources with QueryComposition

Topics: Web Api
Mar 22, 2011 at 8:46 PM

I think a common use of the QueryComposition attribute will be to return IQueryable implementations from existing ORMs like NHibernate or EF. If you do things like the code above,

[QueryComposition]
[WebGet]
public IEnumerable<Customer> GetAll()
{
return efContext.Customers;
}
You can not dispose the EF context in the same method, or otherwise the WCF pipeline will not able to use the IQueryable implementation. 
A solution for this will probably allow the developer to implement IDisposable at resource level, and make WCF to call the Dispose method to release things like the context in this case.
Thanks
Pablo.