In my utility library I have a method:

public X GetOrCreateX()
    X x = (X)HttpContext.Current.Items[key];
    if (x != null)
        return x;
    x = new X();
    HttpContext.Current.Items[key] = x;
    return x

X is IDisposable.

I want my X to be disposed as soon as request ends. Is there any way to add EndRequest handler to HttpContext.Current right in GetOrCreateX method? Is it possible? Or I have to use IHttpModule or global.asax with no options?

Related posts

Recent Viewed