KEMBAR78
Add HttpResults to the ImplicitUsings of ASP.NET Core projects so TypedResults/Results<T1,T2> don't need an explicit using by sander1095 · Pull Request #47231 · dotnet/sdk · GitHub
Skip to content

Conversation

@sander1095
Copy link

@sander1095 sander1095 commented Mar 3, 2025

This issue is related to dotnet/aspnetcore#60337, in which we enrich the webapiaot template with OpenAPI by default, which can be disabled with --no-openapi. In order to write endpoints with correct OpenAPI metadata, TypedResults and Results<T1,T2> are used, which are part of the Microsoft.AspNetCore.Http.HttpResults namespace.

The build of the mentioned PR failed because the usings for the mentioned types were not available. While researching this, I found out that this is because ImplicitUsings for ASP.NET Core projects doesn't add these types.

There are 2 options:

  • Require every (new) project to add the HttpResults namespace with an explicit using
    • And to every file when endpoints are later on separated by files and TypedResults are used.
  • Add Microsoft.AspNetCore.Http.HttpResults to the list of usings that should be globally added when ImplicitUsings is enabled, which is what this PR does. This prevents a bit of "using pollution", and is therefore (in my opinion) the preferred approach

…xplicitly need to be added to Program.cs of Minimal API projects, reducing clutter
@sander1095
Copy link
Author

Closing because the decision has been made in the mentioned PR to stick with explicit usings

@sander1095 sander1095 closed this Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-WebSDK untriaged Request triage from a team member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant