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 implementing IDisposable revisited

See original GitHub issue

I know in #3 it was clear that implementing IDisposable for the AutofacServiceProvider was not desired. Now that the generic hosting is available in .net core 2.1, I’d kindly ask that you rethink this. I’d like to be able to use Autofac to register all my dependencies in a console application, and host it with the generic hosting classes. Unfortunately, since the AutofacServiceProvider doesn’t implement IDisposable, the console host has a deadlock when I try to terminate my process with CTRL-C.

I think Microsoft’s implementation is mostly to blame for this situation, but adding an option to dispose the container that is built by the AutofacServiceProviderFactory would alleviate it for me. I’d obviously be more than happy to submit a pr with this change, but I didn’t want to do so if you think this is still a bad idea.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
tilligcommented, Aug 16, 2018

I added a bunch of new “assumed behavior tests” to verify what the Microsoft container is currently doing and ensure our AutofacServiceProvider and all are doing the same thing. Most of these are around disposal and assumptions around when/how things get disposed.

I think I have it nailed, so I’ll push this out as a 4.3.0 shortly.

1reaction
tilligcommented, Aug 16, 2018

OK, 4.3.0 is out. Give it a shot and let me know what you think. I’m going to be out until next week so if you find something that needs to be fixed… I can approve PRs from my phone, but actual fixes may have to wait. Help resolving totally broken things is always welcome. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Autofac Documentation
IDisposable ) - Autofac can handle disposing those components for you when the ... Create an AutofacServiceProvider using the container.
Read more >
IDisposable, Done Right
The pattern above for implementing IDisposable ensures that all references are properly disposed and released. Using the finalizer, along with ...
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 >

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