DI with disposable objects
- by sunnychaganty
Suppose my repository class looks like this:
class myRepository : IDisposable{
private DataContext _context;
public myRepository(DataContext context){
_context = context;
}
public void Dispose(){
// to do: implement dispose of DataContext
}
}
now, I am using Unity to control the lifetime of my repository & the data context & configured the lifetimes as:
DataContext - singleton
myRepository - create a new instance each time
Does this mean that I should not be implementing the IDisposable on the repository to clean up the DataContext?
Any guidance on such items?