Glimpse/Glimpse — pull request #709 by CGijbels (2014-01-20 19:28:38+00:00)
Title: WIP - Introducing `GlimpseRequestContext` in combination with a `GlimpseRequestContextHandle` for lifetime management

This pull request is a work in progress so that it can be reviewed before before applying it to the _version-2_ branch.

The goal of the changes is to remove the usage of the `CallContext` like we have today and like they were initially introduced in _version-2_ to store the `requestResponseAdapter` instances but it might become problematic when non serializable stuff is stored in the _request store_

This proposal still uses the `CallContext` but only to store a string aka _the glimpse request id_ , which will be used to retrieve the corresponding `GlimpseRequestContext` that contains the corresponding `IRequestResponseAdapter` instance. This is made available by the `GlimpseRumtime.Instance.CurrentRequestContext` so that the current _faulty or not yet figured how to implement_ features of the `GlimpseConfiguration.TimerStrategy` and `GlimpseConfiguration.RuntimePolicyStrategy` can behave as expected.

The changes have their impact on the `GlimpseRuntime` which exposes the `GlimpseRequestContextHandle` to the framework providers (the `HttpModule` and the `GlimpseMiddleware`) so that they can maintain the lifetime of that handle which will make sure the current `RequestResponseContext`, which is now stored in a static collection, will be removed to avoid memory leaks.

While working on it, I added some remarks of things we need to clarify (I'll add some commit comments to point to some of them)

Below I'll summarize changes made to particular classes:

- __AspNetRequestResponseAdapter__ : Removed the dependency on `HttpContext.Items` and the `CallContext` . Also the logic with respect to checking whether or not the HTTP headers were already sent has been moved into this class as well as the `GenerateGlimpseScriptTags()` method. All of this functionality was previously part of `HttpContextExtensions` class but since we make use of an `IRequestResponseAdapter` it didn't make any sense to extend the `HttpContext`. This extra functionality which is specific for the ASP.NET context has been pulled into an `IAspNetRequestResponseAdapter` interface

- __HttpModule__ and __GlimpseMiddleware__ : The necessary changes have been made to cope with the lifetime of the `GlimpseRequestContextHandle`

- __GlimpseConfiguration__ : Implementations have been provided for the `TimerStrategy` and the `RuntimePolicyStrategy`

- __GlimpseRequestContext__ , __ActiveGlimpseRequestContexts__ and __GlimpseRequestContextHandle__ : these types track the _current request_ by storing it in a static collection managed by the `ActiveGlimpseRequestContexts` and for which the lifetime (aka to make sure the contexts are removed as soon as possible from that static collection once they are not needed anymore) is tracked by the `GlimpseRequestContextHandle` . For these classes the necessary tests have been added as well

- __Glimpse tab__ : A Glimpse tab that shows some details about the collection of active request contexts (in case a cleanup would not happen, it will be made visible there . This tab can later on be extended to show even more internals of Glimpse (inception like :wink:)