I have following abstract class and need to implement IDisposable to make sure that DbContent will be disposed all the time properly.
public abstract class DataRepositoryBase<T> : DataRepositoryBase<T, MainDbContext>
where T : class, IIdentifiableEntity, new()
{
}
what is the best way to achieve that?
Please NOTE: I'm greatly aware on how to use IDisposable in concrete classes but implementation of this functionality in the abstract class - not very clear
I would take the implementation provided in this answer:
Proper use of the IDisposable interface
And in derived types override the Dispose(bool disposing)
method if the derived type needs to also dispose of stuff, remembering to call base. If it doesn't need to, then simply do nothing with the base implementation.
Make sure it makes sense to expose the need to call Dispose
on this type's public contract, it could be a sign of a leaked abstraction (though not always).
This would at the very least be a good start.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments