Can an ASP.NET web application have only one Init and one Dispose method or can I implement these per class for those which I want to associate such methods?
More specifically I have Customer component and a CustomerRecord classes and would like to implement Init and Dispose methods in both of them.
What is the proper way to do this?
Requirement:
I want to have independent Init and Dispose methods for each aforementioned class.
For classes that should be disposable, by exposing a public
Disposemethod, theIDispsableinterface must be implemented for ‘disposability’ to be effective out of the scope of explicit user disposal. This has been covered many times in many places, including here, for example:Note that the destructor (the method starting with the tilde
~) may not be necessary, but read the details from the answer I linked above for clarity on the situation of what and why – this just answers your question directly.As for an
Initmethod, are you referring to a constructor?If so, then look at the destructor in the above example; a constructor (or initialiser) can be defined in the same way minus the tilde and, generally, plus an explicit access modifier (
public,private, et cetera), for example: