Skip to content

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

Merged
eerhardt merged 8 commits into
dotnet:mainfrom
bjorkstromm:feature/GH-43970
Apr 28, 2021
Merged

eerhardt merged 8 commits into
dotnet:mainfrom
bjorkstromm:feature/GH-43970

Conversation

@bjorkstromm

Copy link
Copy Markdown
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
@ghost

ghost commented Apr 25, 2021

Copy link
Copy Markdown

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

ghost commented Apr 25, 2021

Copy link
Copy Markdown

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: -

@davidfowl

Copy link
Copy Markdown
Member

This looks good but needs tests

@bjorkstromm

Copy link
Copy Markdown
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

@davidfowl davidfowl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@eerhardt eerhardt left a comment

Copy link
Copy Markdown
Member

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
@davidfowl

Copy link
Copy Markdown
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