As a rule, abstract dependencies should not be inferred from IDisposable , because it will be Leaky Abstraction . A dependency may or may not contain unmanaged resources that are implementation-specific. In any case, the container must control the lifetime , so for him this does not correspond to the consumer - he does not know the dependence on the lifetime: it could be used with other consumers, and in this case it would be destructive to prematurely dispose of .
However, a DataContext (LINQ to SQL?) Presents another problem, since it already implements IDisposable, and you cannot very well change this because it is defined in BCL.
You can correctly implement IDisposable for your repository, but that means that for all repositories and datacontext you need to match the lifetime .
Another alternative is to simply ignore that you are holding onto a one-time resource, but if you do, you will need to make absolutely sure that Unity will correctly manage the DataContext at the appropriate time - but since you plan on using the Singleton lifetime, this should not be a problem .
source share