Zygimantas
Zygimantas

Reputation: 8807

ASP.NET Core 3.0 endpoint routing and custom middlewares

What is the replacement of this code in .NET 3.0 with endpoint routing?

app.UseRouter(a => a.MapMiddlewareGet(
    "middleware1",
    b => b.UseMiddleware<Middleware1>()));

or should it be left like this:

app.UseRouter(a => a.MapMiddlewareGet(
    "middleware1",
    b => b.UseMiddleware<Middleware1>()));
app.UseEndpoints(a => a.MapControllers());

Upvotes: 5

Views: 868

Answers (1)

pavinan
pavinan

Reputation: 1371

I think the following code helps you. I have tested and it is working.

app.UseEndpoints(endpoints =>
{
    var newAppbuilder = endpoints.CreateApplicationBuilder();
    newAppbuilder.UseMiddleware<Middleware1>();

    endpoints.MapGet("middleware1", newAppbuilder.Build());
});

Upvotes: 1

Related Questions