AspNetCore.Docs/aspnetcore/diagnostics/asp0014.md

1.2 KiB

title description author monikerRange ms.author ms.date uid
ASP0014: Suggest using top level route registrations Learn about analysis rule ASP0014: Suggest using top level route registrations captainsafia >= aspnetcore-7.0 safia 09/27/2022 diagnostics/asp0014

ASP0014: Suggest using top level route registrations

Value
Rule ID ASP0014
Category Usage
Fix is breaking or non-breaking Non-breaking

Cause

Routes can be registered directly at the top-level of a minimal API application.

Rule description

Routes can be registered directly at the top-level of a minimal API application and don't need to be nested within a UseEndpoints call.

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.UseEndpoints(endpoints =>
{
    endpoints.MapGet("/", () => "Hello World!");
});

app.Run();

How to fix violations

To fix a violation of this rule, register the endpoints directly on the WebApplication.

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

When to suppress warnings

Do not suppress a warning from this rule.