I can't wrap my head around this issue, where I am assigning a instance to a static class and variable during Appication_Start
and the variable become null 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 assign an instance to the variable upon Appication_Start
, I would expected that the _appscopeContainer
presists.
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
On Begin_Request
I would build a child container and store it to the HttpContext request cache, and an error will sometimes throw saying that the _appscopeContainer
is null after a few days, I have tried recycling the application and it will behivaour normally.
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim requestContainer As IContainer = IocFactory.Instance.BeginLifetimeScope(Tags.RequestLifetimeScopeTag)
End Sub