-2

In asp.net, instance variables are created for each request. For example if I have a class called CustomerManager and if I create an instance of it on as aspx page, that instance is re-created for each request. I understand that static variables, methods, and cache objects are exempt from this.

Are there any web frameworks in different languages that create instance of an object (non static) once and share it across all the requests?

user3587180
  • 1,241
  • 9
  • 19
  • No, because this is not like ASP.NET works. If you try to elaborate why you need to keep same instance for all requests? What benefits you trying to achive? – Fabio Sep 24 '16 at 23:39
  • I'm not trying to achieve this. I was just curious to know if there any frameworks that do this. If there are such frameworks I wanted to know what sort of applications are those. – user3587180 Sep 24 '16 at 23:43
  • I think you're looking for [Singletone](https://msdn.microsoft.com/en-us/library/ff650849.aspx) | [Implementing Singleton in C#](https://msdn.microsoft.com/en-us/library/ff650316.aspx) – Aly Elhaddad Sep 25 '16 at 02:01
  • Even singleton in asp.net would create a new instance for each request unless they are declared as static – user3587180 Sep 25 '16 at 02:22

1 Answers1

1

You don't need to switch frameworks. In ASP.NET, you could write an HTTP Handler that implements IHttpHandler and sets IsReusable to true. The class instance will be re-used for subsequent requests instead of torn down at the end of the pipeline execution.

A handler can do anything a page can... although you may have to write a bit more code.

Community
  • 1
  • 1
John Wu
  • 47,831
  • 8
  • 41
  • 73
  • Thanks for the answer. I'm not looking to switch frameworks. I'm curious to know if there are any frameworks that run on just one main thread for all the requests. – user3587180 Sep 25 '16 at 04:05