skip to Main Content

I’m creating a Web site using C#/Asp.net. I want to minimize object creation by setting some classes and properties as static. But I don’t want those objects to be reused by subsequent calls to the Web server. I want the static objects to be disposed of as soon as a request has been processed. And if, during processing, a new request comes in, I don’t want the new request to see data in the prior request’s static classes and properties. So, should I be using static or not?

2

Answers


  1. The best thing to manage object creation in an asp.net application is the IoC container. Basically, such a mechanism takes responsibility for object creation and release.

    It allows you to configure how long every object should live. And whether it should be shared across HTTP requests or not.

    Here you can find good examples and explanations of what it is DI doc

    Login or Signup to reply.
  2. I don’t want those objects to be reused by subsequent calls to the Web server … if, during processing, a new request comes in, I don’t want the new request to see data in the prior request’s static classes and properties.

    Then you should not use static objects.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search