Open pavinan opened 4 years ago
Thanks @pavinan. We'll investigating adding these APIs in the next major release.
We have come across a similar problem. Previously you could use UseRouter
and call UseMvc
on both places (while configuring the IRouter
ie. in the pipeline branch and on the main app
branch). This is however not supported with endpoint routing (as far as I know since calling UseEndpoints
on a branched app is not supported).
The way we want to solve this is by using UseWhen
which splits the pipeline and rejoins:
app.UseRouting();
app.UseWhen(c => c.Request.Path.StartsWithSegments("/foo"),
innerApp => innerApp.UseMiddleware<FooMiddleware>()));
app.UseEndpoints(endpoints => endpoints.MapControllers())'
Is this the right way to go?
As an addition to MapMiddlewareRoute
(which branches the pipeline) we would find an analogous UseMiddlewareRoute
(if it would rejoin and use the MapControllers
from the original branch) useful if such a construct would be possible.
@shadow-cs I was able to work around this today as follows:
app.UseEndpoints(endpoints =>
{
var subApp = app.New();
subApp.UseMiddleware<FooMiddleware>();
endpoints.Map("/foo", subApp.Build());
}
Edit: This probably doesn't stack to let you augment existing routes like controllers though.
We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.
MapMiddleware extensions are missing in new Endpoint.
In previous routebuilder it has MapMiddlewareRoute, MapMiddlewareGet, MapMiddlewarePost, MapMiddlewarePut, MapMiddlewareDelete.
I have considered the following alternative.