How to manage resources declared in a static class in an ASP.NET web application

I refer to a third-party library in an ASP.NET MVC application because the design of a library that requires a class (say, ClassA ) must be created only once and must be deleted after use. So, in my MVC application, I defined a static class and created an external ClassA inside ( ClassA ). But what is the efficient way to dispose of a single instance of ClassA ? I believe Application_End is the wrong place. but in which case is the method the right place for this?

I should review the iisreset scripts, repeat the application pool cycle, and any other cases where the server is stopping or restarting, and to make sure the resource is located correctly.

+6
source share
1 answer

My suggestion. First create a private field for ClassA. Encapsulates it in a property that checks if the field is null. If null, create a new instance. If not, delete the object and return a new instance of ClassA. Does it make sense?

0
source

All Articles