3

As per my understanding, we need to use the next(context) to call the next request delegate/middleware. I have gone through multiple online resources, but have not found an exact difference between next(context) and next.Invoke(context).

I want to use next(context) in place of next.Invoke(context) in existing code written by another person based on my learning. If I am using next() instead of next.Invoke(context), everything is working fine. I want to know if it will impact anything or there is any difference between these two calls.

Kirk Larkin
  • 84,915
  • 16
  • 214
  • 203
DSR
  • 592
  • 5
  • 14

1 Answers1

5

next is a RequestDelegate in this context, hence there is no functional difference between next(context) and next.Invoke(context). next(context) will be translated to next.Invoke(context).

Please note that you'll need to await next(context) in the same situations as with next.Invoke(context).

More info on custom middleware: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write?view=aspnetcore-5.0

Roar S.
  • 8,103
  • 1
  • 15
  • 37