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

Adds extension method to create service scope that implements IAsyncDisposable. #51840

Merged
merged 8 commits into from
Apr 28, 2021

Conversation

bjorkstromm
Copy link
Contributor

  • Introduces a new type AsyncServiceScope that implements IServiceScope and IAsyncDisposable. The type just wraps an existing IServiceScope instance, which it tries to cast it to an IAsyncDisposable when DisposeAsync is called.
  • Adds netstandard2.1 target to avoid bringing in System.Threading.Tasks.Extensions and Microsoft.Bcl.AsyncInterfaces if not needed.
  • Fixes Make CreateScope return ServiceScope that also implements IAsyncDisposable #43970

Can't remember (nor find info) whether we agreed on putting this in Microsoft.Extensions.DependencyInjection or Microsoft.Extensions.DependencyInjection.Abstractions. I added it to Microsoft.Extensions.DependencyInjection.Abstractions, which however only targeted net461 and netstandard2.0. This means that we have to pull in System.Threading.Tasks.Extensions (for ValueTask) and Microsoft.Bcl.AsyncInterfaces (for IAsyncDisposable). Because of this, I think it would be wise to add a netstandard2.1 target so that these dependencies can be ignored on net5 and newer,

// cc @davidfowl

…isposable.

- Introduces a new type AsyncServiceScope that implements IServiceScope and IAsyncDisposable. The type just wraps an existing IServiceScope instance, which it tries to cast it to an IAsyncDisposable when DisposeAsync is called.
- Adds netstandard2.1 target to avoid bringing in System.Threading.Tasks.Extensions and Microsoft.Bcl.AsyncInterfaces if not needed.
- Fixes dotnet#43970
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Apr 25, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Introduces a new type AsyncServiceScope that implements IServiceScope and IAsyncDisposable. The type just wraps an existing IServiceScope instance, which it tries to cast it to an IAsyncDisposable when DisposeAsync is called.
  • Adds netstandard2.1 target to avoid bringing in System.Threading.Tasks.Extensions and Microsoft.Bcl.AsyncInterfaces if not needed.
  • Fixes Make CreateScope return ServiceScope that also implements IAsyncDisposable #43970

Can't remember (nor find info) whether we agreed on putting this in Microsoft.Extensions.DependencyInjection or Microsoft.Extensions.DependencyInjection.Abstractions. I added it to Microsoft.Extensions.DependencyInjection.Abstractions, which however only targeted net461 and netstandard2.0. This means that we have to pull in System.Threading.Tasks.Extensions (for ValueTask) and Microsoft.Bcl.AsyncInterfaces (for IAsyncDisposable). Because of this, I think it would be wise to add a netstandard2.1 target so that these dependencies can be ignored on net5 and newer,

// cc @davidfowl

Author: bjorkstromm
Assignees: -
Labels:

area-Extensions-DependencyInjection, new-api-needs-documentation

Milestone: -

@ghost ghost added this to Active PRs in ML, Extensions, Globalization, etc, POD. Apr 25, 2021
@davidfowl
Copy link
Member

This looks good but needs tests

@bjorkstromm
Copy link
Contributor Author

This looks good but needs tests

This looks good but needs tests

Tests added to Microsoft.Extensions.DependencyInjection.Tests

@davidfowl davidfowl added this to the 6.0.0 milestone Apr 27, 2021
Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the contribution!

@eerhardt eerhardt merged commit 41f3d48 into dotnet:main Apr 28, 2021
ML, Extensions, Globalization, etc, POD. automation moved this from Active PRs to Done Apr 28, 2021
@davidfowl
Copy link
Member

Excellent work @bjorkstromm Im looking forward to more changes like this

@bjorkstromm bjorkstromm deleted the feature/GH-43970 branch April 28, 2021 03:42
@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make CreateScope return ServiceScope that also implements IAsyncDisposable
5 participants