DryIoc icon indicating copy to clipboard operation
DryIoc copied to clipboard

IAsyncDisposable is not being called after container.Dispose

Open JanVargovsky opened this issue 5 years ago • 4 comments
trafficstars

I haven't found that IAsyncDisposable is actually supported and thus not being called. I'm using implementation of IHostedService, so I can run something like

IServiceProvider _services; // injected and stored as a field

public async Task StopAsync(CancellationToken cancellationToken)
{
    foreach (var disposable in _services.GetServices<IAsyncDisposable>())
        await disposable.DisposeAsync();
}

but it is still just a workaround. Do you have a recommended approach how to deal with it? One option that comes to my mind is implement also IDisposable that recalls DisposeAsync but it covers only my implementations and I have to (should) dispose 3rd party code also that is registered too.

JanVargovsky avatar Feb 13 '20 14:02 JanVargovsky

IAsyncDisposable is not yet supported. I am open for PRs. This should probably need to be added to Container and to Scope. We need to ensure that the task machinery is not affecting performance of the old Dispose implementations, especially the one for the Scope.

dadhi avatar Feb 13 '20 17:02 dadhi

The inspiration from the LightInject https://github.com/seesharper/LightInject/pull/573/files

dadhi avatar Sep 12 '22 20:09 dadhi

Hi, We're using the Prism WPF library for our application. Prism uses DryLoc. Any ETA on when we can expect support for IAsyncDisposable in DryLoc?

jeroenwalter avatar Oct 17 '22 12:10 jeroenwalter

@jeroenwalter When time permits. Hope that it will be soon. This is the current feature I am working on.

dadhi avatar Oct 17 '22 14:10 dadhi