After reading "Pro ASP.NET Core" about the middleware pipeline, I'm struggling to understand its implementation.
If it is implemented recursively, isn't there a risk of stack overflow?
If it's not implemented recursively, and the ASP.NET Core platform calls each middleware component sequentially, how does it manage to continue executing subsequent code after the "next()" function is called?
I came across a middleware pipeline flowchart in Microsoft's documentation, and its calling process seems to follow a recursive pattern. Assuming that the Invoke function of each middleware calls "next", when the first middleware calls "next", it goes into the second middleware, and so on until the last middleware calls its "next". This would create a stack of calls that is released layer by layer, and the program flow returns to the front to execute the code after each "next".
But that would be a stack overflow (if there are thousands of middleware), and I don't believe that would be the implementation, and if it's called sequentially by asp.net core, how does it manage to continue executing the code after "next"?
However, this approach could potentially lead to a stack overflow, especially if there are thousands of middleware components. I find it hard to believe that this is the actual implementation. On the other hand, if middleware components are called sequentially by ASP.NET Core, how does the platform manage to continue executing the code after each "next" call?
