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
c # vb.net asp.net


source to share


No one has answered this question yet

See similar questions:

51
ASP.NET lifetime static variable

or similar:

1480
Is there a reason for C # to reuse variable in foreach?
1197
Static readonly vs const
1
VB.net random numbers on different labels
0
VB.NET variable check
0
Replacing each letter
0
How to set limit text boxes and show message box when maximum limit is reached VB.Net
0
Gridview - add row using footer
0
Default.aspx.vb and Forms.Masters btnSignIn and I need to change this code so when I login I can login without entering username or password
-2
Change background color using combobox from another form in Visual Basic
-4
Send bulk email to VB.NET Recopients. Emails will be downloaded excel



All Articles
Loading...
X
Show
Funny
Dev
Pics