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
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
Then you should not use
static
objects.