.net: Should our开发者_运维知识库 custom Data Access Layer classes implement Idisposable? They use mainly a Database as a Data Store for storing/retrieving data?
Thank you
Dispose is primary used to free unmanaged resources. For instance sockets, connections to databases and file handles.
If you do not keep track of any unmanaged resources yourself you do not need to implement IDisposable
since all resources are freed when the DbConnection
is collected by the GC.
I would recommend you to do two things:
a) If you have a DbConnection as a member variable, implement IDisposable
and dispose the connection in the Dispose method. This will only work if you are using the using
keyword when using your DAL.
b) Start using using
anywhere you can to make sure that resources are freed as soon as possible.
精彩评论