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 Extensions to Http.TypedResults #47050

Closed
dnperfors opened this issue Mar 6, 2023 · 5 comments · Fixed by #47285
Closed

Add Extensions to Http.TypedResults #47050

dnperfors opened this issue Mar 6, 2023 · 5 comments · Fixed by #47285
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@dnperfors
Copy link
Contributor

dnperfors commented Mar 6, 2023

Background and Motivation

TypedResults has a very similar api as Results, but it lacks an Extensions property.

This property would be useful for consistency, all endpoints can use TypedResults even when using customized results via an extension. Besides that there seem to be plans the recommend and add a codefixer for using TypedResults where possible. (#45217)

Proposed API

namespace Microsoft.AspNetCore.Http;

public static class TypedResults
{
+    public static IResultExtensions Extensions { get; } = new ResultExtensions();
}

Usage Examples

app.MapGet("/",  () => TypedResults.Extensions.CustomResult());

Alternative Designs

Alternatively a new specific interface could be used instead:

namespace Microsoft.AspNetCore.Http;

+ public interface ITypedResultExtensions { }

public static class TypedResults
{
+    public static ITypedResultExtensions Extensions { get; } = new ResultExtensions();
}

Risks

When going for the proposed solution, existing extensions automatically become available, even if they are not 'Typed'.

@dnperfors dnperfors added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 6, 2023
@adityamandaleeka adityamandaleeka added api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Mar 6, 2023
@adityamandaleeka adityamandaleeka added this to the .NET 8 Planning milestone Mar 6, 2023
@ghost
Copy link

ghost commented Mar 6, 2023

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.

@ghost
Copy link

ghost commented Mar 6, 2023

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@halter73
Copy link
Member

API Review Notes:

  • Why did we add Results.Extensions in the first place? Mostly discoverability of custom IResult types.
  • The workaround is just continue using Results.Extensions and return strong types from custom IResult types.
  • Is it confusing to include an Extensions in both places? It might less confusing because it's the only member of Results that's not in TypedResults.
  • Do we like the alternative design? It provides more flexibility. You could have one IResult-returning method better for multiple return points in a lambda, and one that's type. It could be confusing if extensions that showed up on one didn't on the other though. And it's a lot more ceremony for custom IResult authors.

API Approved as proposed!

namespace Microsoft.AspNetCore.Http;

public static class TypedResults
{
+    public static IResultExtensions Extensions { get; } = new ResultExtensions();
}

@halter73 halter73 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 Mar 16, 2023
@davidfowl
Copy link
Member

We might be getting extension everything in C# 12, so hopefully, this will be obsolete in the future.

cc @jaredpar @MadsTorgersen

@dnperfors
Copy link
Contributor Author

I can provide a PR with the implementation.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 19, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants