autofac/Autofac.Extensions.DependencyInjection

Components registered with RegisterInstance are only Dispose()d or DisposeAsync()ed when actually used

Tragetaschen opened this issue · 1 comments

Follow up on https://github.com/autofac/Autofac/issues/1078
Describe the bug

class MyDisposable : IDisposable
{
    public void Dispose() { }
}
//
public void ConfigureContainer(ContainerBuilder builder)
    => builder.RegisterInstance(new MyDisposable());

With just these registrations and no other components that require MyDisposable, the instance is not disposed when gracefully exiting the program. (yes, my use case is more complex than that... :)

As a workaround, I can add a .AutoActivate().As<MyDisposable>() to the registration. This results in the instance being disposed on graceful program exit.

To reproduce
https://github.com/Tragetaschen/autofac-does-not-dispose

Assembly/dependency versions:
I have reduced it using Autofac 5 / Extensions 6, but the observable behavior of not being disposed is the same in 4.9.4 / 5.0.1.

Additional context
Add any other context about the problem here.

Duplicate #68