General / static variable in Global.asax separately for request?

I have some ASP.NET web services for which they only need a common common helper class to instantiate one instance for each server. It is used for simple data translation, but spends some time while loading things from the web.config file, etc. Helper class 100% thread safe. Think of it as a simple service call library. I would include all the methods in the class, but I want to load the initial configuration from web.config. We have deployed web services for IIS 6.0 and using the application pool with a 15-person web garden.

I declared the helper class as a Private Shared variable in Global.asax and added the lazy Shared ReadOnly property as follows:

Private Shared _helper As MyHelperClass

Public Shared ReadOnly Property Helper() As MyHelperClass
    Get
        If _helper Is Nothing Then
            _helper = New MyHelperClass()
        End If
        Return _helper
    End Get
End Property

MyHelperClass(), , , . , ASP.NET, MSDN .

, Application("Helper"), Cache("Helper"), , .

+3
3

, , , . - . HttpContext.Current . VB , , , .

0

. global.asax:

  void Application_Start(object sender, EventArgs e)
  {
    Application.Add("MyHelper", new MyHelperClass());
  }

:

  MyHelperClass helper = (MyHelperClass)HttpContext.Current.Application["MyHelper"];
  helper.Foo();

MyHelperClass, . Application_Start, HttpApplication, .

+3

- . . , , , , .

, .

0

Source: https://habr.com/ru/post/1696863/


All Articles