elsa-core
elsa-core copied to clipboard
IAsyncDisposable in scoped dependencies of custom activities
When scoped services are getting injected in custom activities, only IDiposable
is currently supported for cleaning up resources of the scoped services.
If a scoped service only supports IAsyncDisposable
a System.InvalidOperationException
exception will be generated indicating the resource cannot be disposed. Although Microsoft recommends to always implement IDiposable
if you implement IAsyncDisposable
to avoid a possible memory leak, it might be nice if the scope also supports IAsyncDisposable
. This is easily achievable by using CreateScopeAsync
instead of CreateScope
.
This is the scope that should be adapted for the injection of services in custom activities: https://github.com/elsa-workflows/elsa-core/blob/f7f340c4aea9c8f2010319f97609eac9ee5874bd/src/core/Elsa.Core/Services/Workflows/WorkflowRunner.cs#L56
When searching in the repository, there are a few other places where it would be possible to migrate to an async scope.