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();
});
Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *