I have a 'context' object that ties itself to HttpContext.Items via a static Current property. This object can be used directly, through expression builders and controls, all being part of the same library.
The issue I'm coming across is that I want to dispose of it's managed resources (WCF clients) when a request ends without using an HttpModule (since it is otherwise not needed). I have implemented the full disposable pattern (with Finaliser), but you can't rely on the GC finalising instances in a timely manner.
I have tried to subscribe a static method to HttpApplication.EndRequest (also PostRequestHandlerExecute) in the objects constructor (with locking to ensure it only happens once), but the event is never dispatched. This is presumably because the instance of HttpApplication changes, though I'm not entirely sure.
Any thoughts on the best way to go about solving this?