C# - 2b - Making MVC models disposable (when you have an Open method).

[C# 2.0]

This is a variation on Tip 2: Making MVC models disposable which you should read and understand first.

Supposing your disposable class has an Open() method. Recommended best practice says you should have a corresponding Close() method. Take the class you modified in Tip 2 and change the Dispose() method from …

… to read:

If the Dispose() method was referenced in a general interface (such as ImodLogin) that reference should be removed.

Now add as the last line of the public Close() method:

Which means that if the class is closed it will also be disposed.


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License