DI with disposable objects
Posted
by sunnychaganty
on Stack Overflow
See other posts from Stack Overflow
or by sunnychaganty
Published on 2010-03-08T19:16:51Z
Indexed on
2010/03/08
19:21 UTC
Read the original article
Hit count: 257
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?
© Stack Overflow or respective owner