In preparation of a GraphQL workshop I'm giving later this week, I was updating my demos to .NET 7. The original demos were written in .NET 5, but with the introduction of minimal API's in .NET 6 I decided to take that route. So I removed my Startup.cs
file and copied everything inside my Program.cs
file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapGraphQL(); | |
}); | |
app.Run(); |
This however resulted in the following error message(which is in fact a warning but I have 'Treat Warnings as Errors' enabled in Visual Studio):
ASP0014: Suggest using top level route registrations
In .NET 6 routes no longer need to be nested inside an UseEndpoints
call, so I can rewrite the code above to get rid of this warning:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapGraphQL(); | |
app.Run(); |
More information: ASP0014: Suggest using top level route registrations | Microsoft Learn