Disposing disposable transient services in Blazor #54376
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
Status: Resolved
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Someone opened this same issue some years ago. However, it was closed and the answer given in that issue appears to be wrong.
In the section Disposal of services in the ASP.NET Core documentation it states: "The container calls Dispose for the IDisposable types it creates. Services resolved from the container should never be disposed by the developer.".
However, this appears to be not the case with Blazor. Whereas the Dispose method of components is called if they implement the IDisposable interface, the injected services (given they are transient) are not disposed. I do believe one of the reasons for a DI container is lifetime management. A component should not be aware of the lifetime of a service it consumes.
Describe the solution you'd like
Injected transient services get disposed once a component gets disposed.
Additional context
I'm not sure if this might even be considered a bug because it contradicts the documentation.
The text was updated successfully, but these errors were encountered: