Skip to content

WebApplicationBuilder and IStartupFilter break routing if split between them #62571

@Deathrage

Description

@Deathrage

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

As described in my comment in: #44599

When calling UseRouting() in IStartupFilter, it will not see endpoints mapped by WebApplication.MapControllers().

// Presume this is nuget
class FooStartupFilter: IStartupFilter {
    public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)  
    => builder => {
        builder.UseRouting();
        builder.Use(next => ctx => {
            // do something with Endpoint.
        });

        next(builder);
    }
}
var builder = ....; // get WebApplicationBuilder

builder.Services.AddTransient<IStarutpFilter, FooStartupFilter>();

var webApplication = builder.Build();

webApplication .MapControllers();

Second middleware in IStartupFilter will not see any endpoints unless UseEndpoints(e => e.MapControllers()) is added.

Expected Behavior

UseRouting in IStartupFilter should be able to access mapped routes that were mapped on WebAppliaction and vice versa.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

Most likely caused by WebApplicationBuilder.cs:395.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions