开发者

.net: Should our custom Data Access Layer classes implement Idisposable?

开发者 https://www.devze.com 2023-02-02 05:39 出处:网络
.net: Should our开发者_运维知识库 custom Data Access Layer classes implement Idisposable? They use mainly a Database as a Data Store for storing/retrieving data?

.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号