-
Notifications
You must be signed in to change notification settings - Fork 10.3k
IResult support in MVC #40639
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
Comments
Thanks for contacting us. We're moving this issue to the |
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:
|
API Review Notes
+namespace Microsoft.AspNetCore.Mvc;
+public class HttpActionResult : ActionResult
+{
+ public IResult Result { get; }
+ public HttpActionResult(IResult result){}
+ public override Task ExecuteResultAsync(ActionContext context){}
+}
|
Here are few name ideas for the next review meeting:
|
API Review: After considering the many additional proposed names, we like the originally proposed That said, we don't expect people to new these up since there's already an implicit conversion effectively when returned from Actions. We will wait for developer feedback to see if the use case of inspecting |
Background and Motivation
Today, with the new
Microsoft.AspNetCore.Http.Results
class is very easy to get confused and implement a Controller Action similar with that, or any other variation of the methods exposed by this class:Also, is very easy to use an
Microsoft.AspNetCore.Http.IResult
custom implementation as a return of a controller action, like this:Both examples will not throw exception but will serialize the class. For the first example the action will return the following payload:
Proposed API
The proposal is the creation of a new
public
action result that will store an instance of theIResult
and call theIResult.ExecuteAsync
method instead instead of using theIActionResultExecutor
to write the Http Response. With this, we will miss all the content-negotiation available in MVC through theObjectResultExecutor
but we will have the correct serialization and all the other components, likeMiddleware
,Filters
etc., will work.The controller's action can return a
Microsoft.AspNetCore.Http.IResult
that will be converted to the newHttpResultsActionResult
when theActionResultTypeMapper.Convert
is invoked. Eg.:The sample action will produce the following payload:
Usage Examples
Controller's action using the
HttpResultsActionResult
Result's filter using the
HttpResultsActionResult
If the proposal #40656 is approved, the results instance could be further inspected, eg.:
Alternative Designs
The new type could have a
private
constructor, that could avoid undesired instantiationOr the new action result could be
internal
instead, that will make this proposal irrelevant, but the feature will be available, however, will not be possible to create Result Filters as shown in the example.The text was updated successfully, but these errors were encountered: