Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Stop registering disposable objects in our controller helper methods #4509

Closed
@javiercn

Description

@javiercn

We have methods on Controller and ControllerBase like
Json(object)`` Ok(object)` that register the result object for disposal automatically by doing the following:

var disposableValue = value as IDisposable;
if (disposableValue != null)
{
    Response.RegisterForDispose(disposableValue);
}

This is problematic because the user has no way of knowing that we are registering something for disposal, so chances are the user registers it for disposal anyways and this behavior might be lost if the user decides to override the method and call base (for example when calling Ok(object)).

As an alternative, it might be possible to provide an ActionFilter that does it for you. That way you can still have this behavior by default if you choose to do so by placing the filter in the list of global filters or putting it on the controllers/actions where you have disposable content but the intention is clear.

To make sure this bug is clear, the goal of this bug is to remove

var disposableValue = value as IDisposable;
if (disposableValue != null)
{
    Response.RegisterForDispose(disposableValue);
}

from the helper methods on our controller and make the user be responsible for registering the objects they return that are disposables.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions