Lifetime of static variable problem in WebForm

I can't get around this issue where I assign an instance to a static class and a variable at the time Appication_Start

, after which the variable becomes empty after a few days.

public static class IocFactory
{
    private static IContainer _appscopeContainer;

    public static void Register(IContainer container = null){
        _appscopeContainer = container
    }

    public static Instance{
        get { return _appscopeContainer; }
    }
}

      

And I am assigning an instance to a variable in Appication_Start

, I expected to be << 23>.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    Dim appContainer As IContainer = new Container()
    'register framework 4.0 class to container...

    IocFactory.Register(appContainer)
End Sub

      

As Begin_Request

I have built a child container and store it in the cache HttpContext requests, and sometimes an error, stating that _appscopeContainer

is null after a few days, I tried to re-use the application, and it will be as usual.

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    Dim requestContainer As IContainer = IocFactory.Instance.BeginLifetimeScope(Tags.RequestLifetimeScopeTag)
End Sub

      

+3


source to share





All Articles