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 IAsyncDisposable integration for ASP.NET Core 3 #778

Closed
dotnetjunkie opened this issue Nov 27, 2019 · 3 comments
Closed

Add IAsyncDisposable integration for ASP.NET Core 3 #778

dotnetjunkie opened this issue Nov 27, 2019 · 3 comments
Labels
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Nov 27, 2019

The documentation describes how to implement async disposal with Simple Injector.

.NET Core 3 now contains an IAsyncDisposable interface. It would be nice if Simple Injector's ASP.NET Core packages could automatically asynchronously dispose its created scoped instances.

Downside, however, is that Simple Injector's integration packages require ASP.NET Core 2.0 or higher, while IAsyncDisposable is only available in .NET Core 3. There are 3 paths to walk here:

  1. Upgrade the integration packages to require ASP.NET Core 3
  2. Add an extra integration package specifically for working with IAsyncDisposable.
  3. Use duck typing.

About the options:

  1. is not an attractive solution, because it blocks ASP.NET Core 2 users from using newer packages and features.
  2. is not an attractive solution, because it makes it much harder for users to find this feature.
  3. downside is internal complexity to achieve this while allowing great performance.
@dotnetjunkie dotnetjunkie added this to the v4.9 milestone Nov 30, 2019
@mbett7

This comment has been minimized.

Copy link

@mbett7 mbett7 commented Dec 8, 2019

or
4. Use Microsoft.Bcl.AsyncInterfaces for ASP.NET Core 2.0

@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Dec 8, 2019

Hi @mbett7,

Thank you for this valuable tip. I ran some tests with this and it indeed does the trick. The package uses type forwarding, which allows the runtime to use the IAsyncDisposable from the package in case the application is .NET Standard < 2.1 and automatically uses the built-in type for .NET Standard 2.1. This is the ideal solution and I'll go with that option.

@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Dec 29, 2019

feature-778 branch created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.