.net core中间件创建中next(context)与await next.Invoke(context)之间的区别

DSR*_*DSR 3 c# asp.net-core-mvc asp.net-core asp.net-core-middleware .net-5

根据我的理解,我们需要使用 next(context) 来调用下一个请求委托/中间件。我浏览了多个在线资源,但没有找到next(context) 和 next.Invoke(context)之间的确切区别之间的确切区别。

我想在另一个人根据我的学习编写的现有代码中使用 next(context) 代替 next.Invoke(context) 。如果我使用 next() 而不是 next.Invoke(context),则一切正常。我想知道这是否会影响任何事情或者这两个电话之间有什么区别。

Roa*_* S. 5

next在此上下文中是 a ,因此和 之间RequestDelegate没有功能差异。将被翻译为.next(context)next.Invoke(context)next(context)next.Invoke(context)

请注意,您需要next(context)在与 相同的情况下等待next.Invoke(context)

有关自定义中间件的更多信息:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write ?view=aspnetcore-5.0