How do you configure a middleware?

A logical component (a class or a method) can be configured into a middleware by registering it under the Configure() method of the Startup class. It can be done as below.

app.UseMiddleware<MyClass>();

for a class which takes a constructor parameter of RequestDelegate and uses it to navigate to next component, or a simple method delegate within the Configure method as.

app.Use(async (context, next) => {
    // some logic
    await next.Invoke();
});

A logical component (a class or a method) can be configured into a middleware by registering it under the Configure() method of the Startup class. It can be done as below.

app.UseMiddleware<MyClass>();

for a class which takes a constructor parameter of RequestDelegate and uses it to navigate to next component, or a simple method delegate within the Configure method as.

app.Use(async (context, next) => {
    // some logic
    await next.Invoke();
});
Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply