question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutofacServiceProvider does not implement IDisposable

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smartscommented, Oct 5, 2016

@tillig I don’t understand this part:

you can’t make it optional.

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.

0reactions
DaveVdEcommented, Aug 24, 2016

Thanks, that makes it clear.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found