Skip to content

Feature Request - Need Something like HttpApplication (that's pooled and assocaited to a thread) #1202

@matlus

Description

@matlus

In old ASP.NET we had HttpApplication (Global) that was tagged to a thread which in turn was pooled by ASP.NET. So effectively, there was one instance of HttpApplication for each pooled thread and thus:

  1. HttpApplication was pool
  2. We had an instance of HttpApplication that was automatically associated to a thread and so no overhead was incurred synchronizing an instance of HttpApplication to a request thread (in our application) or accessing this instance from within an ASP.NET application such as a WebForm, Controller or Handler.

This was very useful, because if we need to pool any of our own classes we could simply create an instance of this class in Global (typically in the Init() method) and assign it to a custom property of Global and this property was directly accessible from a WebForm, Handler or (WebAPI) Controller like so

((Global)HttpContext.Current.ApplicationIstance).MyProperty

Granted all pooled "things" need to be stateless or need to zero out their state at the beginning of every request. The benefit of being able to something like this is:

  1. Throughput and Scale
  2. Reduced pressure on the GC
  3. Improved performance

If provided out of the box - makes it really easy for folks to get these benefits (caveat emptor), just like we were able to do riding on HttpApplication in old ASP.NET

I hope all of this makes sense?

Some code examples below, just in case I've not been clear enough on how I used this in old ASP.NET

The code below shows how one would initialize these pooled objects in Global. The QInsightManager is the property the makes the "pooled" object available to WebPages, Handlers, Controllers etc.

public class MvcApplication : System.Web.HttpApplication
{
    private QInsightManager _qInsightManager;

    internal QInsightManager QInsightManager
    {
        get { return _qInsightManager; }
    }

    public override void Init()
    {
        base.Init();
        _qInsightManager = new QInsightManager();
    }
}

The code below show how this pooled object can be consumed on an MVC ControllerBase class and made available to all descendants very simply.

internal QInsightManager QInsightManager
{
    get { return ((MvcApplication)HttpContext.ApplicationInstance).QInsightManager; }
}

This implementation ensures that we grab the instance associated with the instance of Global that is handling the request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions