Skip to content

[Mvc] Support IAsyncDisposable for controllers and pages #29313

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

Merged
merged 2 commits into from
Jan 19, 2021

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jan 14, 2021

[Fixes #13150]

*Adds async versions of Release to the relevant interfaces in different
factories and activators.

  • The new methods offer a default interface implementation that will
    delegate to the syncrhonous version and just call dispose.
  • Our implementations will override the default implementation and handle
    disposing IAsyncDisposable implementations.
  • Our implementations will favor IAsyncDisposable over IDisposable when
    both interfaces are implemented.
  • Extenders will have to override the new methods included to support
    IAsyncDisposable instances.

The general pattern is that there is a new method on the relevant interfaces that offers a default implementation that delegates to the sync version in the interface. The idea is that extenders will have to do work to support IAsyncDisposable too, but this way we avoid having a breaking change and libraries can add support at their own pace by overriding the default implementation.

We should consider marking the sync versions on the interface as [Obsolete] and point out to the new async versions.

Alternatively we could consider doing a breaking change here since it's very early in the release and we have time to advertise it.

The goal is to minimize the problems due to incompatible libraries for people updating to 6.0.

@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 14, 2021
@javiercn javiercn requested a review from pranavkm January 14, 2021 17:40
Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

This looks greats. Are you planning to update this for view components:

It might also be helpful to throw if an IView instance implements IAsyncDisposable rather than silently no-op. It's invoked in sync code-paths and supporting IAsyncDisposable is far too hard there. (e.g. https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.ViewFeatures/src/TemplateRenderer.cs#L138)

@javiercn
Copy link
Member Author

@pranavkm those are great points.

I was mainly testing the waters to root out any big blockers. The part that I'm more concerned about is the extensibility, but I think the approach I followed offers a reasonable trade-off.

I think we should consider marking the existing sync releaser members as obsolete to hint authors to implement the async capable versions.

@javiercn javiercn force-pushed the javiercn/mvc-async-disposable branch from 32c4a6c to ce4c26b Compare January 19, 2021 14:53
@javiercn javiercn marked this pull request as ready for review January 19, 2021 14:54
{
return Task.FromException(scopeException!);
}
return ReleaseResourcesCore(scope);
Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored this code because it wasn't consistent depending on whether the path was synchronous or async or whether the values were being logged.

* Adds async versions of Release to the relevant interfaces in different
  factories and activators.
* The new methods offer a default interface implementation that will
  delegate to the syncrhonous version and just call dispose.
* Our implementations will override the default implementation and handle
  disposing IAsyncDisposable implementations.
* Our implementations will favor IAsyncDisposable over IDisposable when
  both interfaces are implemented.
* Extenders will have to override the new methods included to support
  IAsyncDisposable instances.
@javiercn javiercn force-pushed the javiercn/mvc-async-disposable branch from ce4c26b to 57c353a Compare January 19, 2021 19:34
@javiercn javiercn merged commit ef8ac1f into master Jan 19, 2021
@javiercn javiercn deleted the javiercn/mvc-async-disposable branch January 19, 2021 22:25
@pranavkm
Copy link
Contributor

new API :|

@ghost
Copy link

ghost commented Jan 19, 2021

Hi @pranavkm. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@javiercn
Copy link
Member Author

javiercn commented Jan 20, 2021

@pranavkm It's life 😃

I've added it to the API review next week

@ghost
Copy link

ghost commented Jan 20, 2021

Hi @javiercn. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@javiercn javiercn added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Jan 25, 2021
@ghost
Copy link

ghost commented Jan 25, 2021

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@@ -20,5 +22,16 @@ public interface IControllerActivator
/// <param name="context">The <see cref="ControllerContext"/> for the executing action.</param>
/// <param name="controller">The controller to release.</param>
void Release(ControllerContext context, object controller);
Copy link
Contributor

Choose a reason for hiding this comment

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

Obsolete and never delete.

@pranavkm pranavkm added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support IAsyncDisposable in MVC
2 participants