In your case, IDisposable is not implemented as much, as you can manually manage your resources.
The usual use of IDisposable is when you open an interface that handles data connections, and you want all the derived classes to be located when they were made.
Consider this:
public interface IDataCtx { void CallDB(); } public class MyDataCtx : IDataCtx { private SqlConnection dc; public MyDataCtx() { dc = new SqlConnection(); dc.Open(); } public void CallDB(); { dc.Something(); } }
Lets you do something like this:
IDataCtx ctx = new MyDataCtx(); ctx.CallDB();
But wait, what about this open connection? Oh!
If you made IDataCtx : IDisposable (and implemented the code in your derived ctx), you can do this:
IDataCtx ctx; using (ctx = new MyDataCtx()) { ctx.CallDB(); }
Ensuring that any implementation of IDataCtx that you use will always be deleted (even in the event of an exception).
That I use it anyway. (plus it's just good practice).
source share