I see in many examples the example of MVC , Repository , Unit of Work, and EF , for example here , that both interfaces and classes implement the IDisposable interface. I assume that this interface provides only the Dispose() method with two overloads.
However, in many other examples made by senior programmers, I do not see such an implementation. Actually, it seems logical to me that one component is rejected with every web request, since each request receives an instance of the brand new controller.
Or, even if this is not the case, I assume that using the dependency injection infrastructure such as Ninject , we delegate all these removal tasks to the platform itself.
It may also be that the implementation of IDisposable is required in an older version of the EF or MVC framework.
Can anyone point me in the right direction?
UPDATE
Automatic deletion of context can be seen in a multilevel application using the Service and the Repository . Suppose we return IQueryable<T> objects from both components, if we try to populate the objects from the controller, iterate over its elements or call the ToList() method, we get a runtime error indicating that the context is unreachable (closed)
source share