SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Support IAsyncDisposable in bindings

Open idg10 opened this issue 2 years ago • 1 comments

Link to Feature Request

https://support.specflow.org/hc/en-us/community/posts/4410211637521-Support-IAsyncDisposable-in-bindings

Implementation Idea

Support for this needs to be implemented in BoDi, because that's what performs the actual disposal. To enable this, I've created https://github.com/SpecFlowOSS/BoDi/pull/51

If that PR gets accepted into BoDi, the minimal implementation of this feature in SpecFlow would just be to upgrade to the version of BoDi that supports IAsyncDisposable.

However, it would be better to do slightly more than that, because in that minimal case, SpecFlow projects would continue to dispose containers using non-async IDisposable.Dispose. And although https://github.com/SpecFlowOSS/BoDi/pull/51 does support disposing IAsyncDisposable objects even when the container is disposed synchronously, this inevitably lead to "sync over async", which is best avoided.

So it would be better to modify SpecFlow so that when it disposes the BoDi container, it does so with IAsyncDisposable.DisposeAsync, returning a Task up to whichever test framework is in use. That way it's async all the way up, and we avoid any risk of sync over async.

But it would be good to get a steer on whether you're actually interested in taking such a PR before I do the work!

idg10 avatar Mar 18 '22 16:03 idg10

Answered in the BoDi PR

SabotageAndi avatar Mar 21 '22 14:03 SabotageAndi