c# - Singleton and HttpApplicationState -


In a web app, I should have only one example of a process called a processorener. One way is to make a singleton in other ways to use HTMLPTC status to make sure that I always use the same example, such as:

  public static process Manager Process Manager {HTTPAPTTTPTP = HTTPTT Buy. Application; If (application-status ["process manager"] == blank) {applicationState ["ProcessManager"] = new processor (); } Returns (Process Manager) ApplicationState ["ProcessinManager"]; }}  

Which method is better and why?

On the details given by you, I will choose Singleton as it does not have the dependence on HttpContext.Current. And ASP can be used outside the net pipeline (for example, when you want to write the unit as a test.)

(On one hand, when you set something in the appstate So you need to call it first, and then unlock () after writing it, listen to it To make sure that this thread is safe.)

Optionally, when you make your processor, allow HTTPTontex injection, such as you can use it with touch HTTPTax.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -