Skip to content

Fixer/Analyzer: Remove UseEndpoints() and hoist route registrations top level to WebApplication #35759

Closed
@davidfowl

Description

@davidfowl

With the new hosting model, it's possible to register routes top level instead of using UseEndpoints. To help customer learn about this, we can have an fixer that can hoist the route registrations to hang off WebApplicatin:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

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

We would suggest this:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

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

app.Run();

Stretch goal is to also remove UseRouting but we would need to only remove it if it wasn't intentionally put top level (like set to re-run middleware).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-hostingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions