-
|
I have a unit test project to ensure that all of the routes used in my API client library can be resolved to actual endpoints in the API project. To do that, I use the registered If I use If I switch to using top-level route registrations, then the Is this expected? Is the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hi! 👋 What you’re seeing is expected behavior with top-level route registrations in ASP.NET Core 7+. Here’s why:
So, EndpointDataSource is not obsolete, just less straightforward with top-level minimal API registrations. Using app.DataSources is the modern way to access all endpoints for inspection. Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
|
That’s a totally reasonable workaround 👍 — and you’re right, IEndpointRouteBuilder is not registered in DI by default. That’s intentional: it’s considered a startup-time construct, not a runtime service. In normal apps, endpoints are meant to be consumed via routing/middleware, not queried from DI later, which is why WebApplication itself isn’t exposed automatically. For tests specifically, your “static WebApplication” approach is a pragmatic solution and perfectly valid
This avoids needing IEndpointRouteBuilder entirely and works for both controllers and minimal APIs.
|
Beta Was this translation helpful? Give feedback.
Hi! 👋
What you’re seeing is expected behavior with top-level route registrations in ASP.NET Core 7+. Here’s why: