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 (original) (raw)
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.
- And to every file when endpoints are later on separated by files and
- Add
Microsoft.AspNetCore.Http.HttpResults
to the list of usings that should be globally added whenImplicitUsings
is enabled, which is what this PR does. This prevents a bit of "using
pollution", and is therefore (in my opinion) the preferred approach