AutofacServiceProvider does not implement IDisposable
See original GitHub issueI’m finding that my SingleInstance registered instances are not disposed after my ASP.NET web app closes. I narrowed it down to where the host is supposed to dispose of the ServiceProvider and it seems it tries to cast the provided ServiceProvider to IDisposable
:
https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs#L215
Since AutofacServiceProvider does not implement IDisposable, there’s no way for the host to dispose of the root container, causing my instances to remain undisposed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
AutofacServiceProvider implementing IDisposable revisited
I'd like to be able to use Autofac to register all my dependencies in a console application, and host it with the generic...
Read more >Dependency Injection and IDisposable
Letting it implement IDisposable in that case is dangerous, because anyone can call Dispose on it causing the application to break. If you...
Read more >CA1063: Implement IDisposable correctly (code analysis)
The System.IDisposable interface is not implemented correctly. Possible reasons for this include: IDisposable is reimplemented in the class.
Read more >How to use IDisposable in ASP.NET Core
This article talks about the many ways you can dispose of objects that implement the IDisposable interface in ASP.NET Core 6.
Read more >Autofac Documentation
This TodayWriter is where it all comes together. // Notice it takes a constructor parameter of type. // IOutput - that lets the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tillig I don’t understand this part:
Why not? .NET has made disposal optional in the case of
StreamReader
. There’s a Boolean value specified in constructor which determines whether the stream’s lifetime operates in conjunction w/ the lifetime of the reader or is controlled externally. So you definitely can make it optional.Thanks, that makes it clear.