IDisposable
The .NET interface with a single Dispose method, implemented by types that own something the garbage collector cannot clean up, such as a file, socket or database connection.
In more detail
Whoever creates a disposable object is responsible for disposing it. For objects the dependency injection container creates, the container disposes them when their scope ends.
Related terms
- using declaration — A local variable declared with using, as in using var stream = File.OpenRead(path);, whose Dispose method runs automatically at the end of the enclosing scope.
- garbage collection — The automatic freeing of memory held by objects that the program can no longer reach.
- DbContext — The EF Core class that represents a session with the database: it tracks entities, translates queries and saves changes as one unit of work.
- service lifetime — How long the container keeps and reuses an instance of a service: transient, scoped or singleton.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- Code Quality: .editorconfig and Roslyn Analyzers — Modern .NET Core, C# & Enterprise Microservices
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices