Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IAsyncDispose support #51

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

idg10
Copy link

@idg10 idg10 commented Mar 18, 2022

Although #49 was closed on the grounds that SpecFlow "won't probably use it for a long time", @SabotageAndi did say:

But that doesn't mean, that we would not accept a PR for it

So here's a PR for it.

This necessarily expands the set of target frameworks. Previously, the target frameworks were net45 and netcoreapp2.0, we need to add netcoreapp3.1 because each of these has a different relationship with IAsyncDisposable

  • net45: no support available
  • netstandard2.0: implemented via Microsoft.Bcl.AsyncInterfaces NuGet package
  • netcoreapp3.1: built into .NET runtime class libraries

If we continued to target only netstandard2.0, we'd be introducing an unnecessary dependency on Microsoft.Bcl.AsyncInterfaces for any apps using .NET Core 3.1 or later. so although .NET Core 3.1 does of course support netstandard2.0, it's better to provide a .NET Core 3.1 target that doesn't need the extra reference to get IAsyncDisposable.

@idg10
Copy link
Author

idg10 commented Mar 18, 2022

I've opened this in draft mode because I don't yet know whether you would like SpecFlowOSS/SpecFlow#2575 to be implemented. That's the only reason I'm looking to add this.

If you do want that, I want to prototype the SpecFlow side of the implementation to the point that it can validate that the BoDi changes in this PR are sufficient. I was aiming to set this to "ready for review" once I've done that validation.

@@ -705,7 +711,12 @@ public void RegisterInstanceAs(object instance, Type interfaceType, string name

private static object GetPoolableInstance(object instance, bool dispose)
{
return (instance is IDisposable) && !dispose ? new NonDisposableWrapper(instance) : instance;
bool implementsDisposable =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the original code is that way, but could you use proper ifs here?
With the pragmas this gets unreadable for me. No idea what is going on.

@@ -1008,16 +1019,59 @@ public void Dispose()
{
isDisposed = true;

#if !ASYNC_DISPOSE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please not use negative pragmas

container.ShouldImplement<IAsyncDisposable>();
}

[Test/*ExpectedException(typeof(ObjectContainerException), ExpectedMessage = "disposed", MatchType = MessageMatch.Contains)*/]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment somehow relevant?

@SabotageAndi
Copy link
Contributor

The comment was from a time when SpecFlowOSS/SpecFlow#1614 was way in the future.
As I commented today there, with the retirement of the SpecFlow+ Runner, the biggest blocker for it is gone.

So I think, when async/await is fixed in SpecFlow, this PR is useful.
I don't know if it is already making sense to bring this to SpecFlow, as for me the async/await support in SpecFlow is simply not finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants