Multiple ways to short-circuit pipeline is a poor design and should be reconsidered
Summary
Having the ability to call Run on the pipeline is confusing because you can have multiple calls to it and get no error, and the last element in the pipeline is effectively a Run anyway. Run has no logical difference to Use if the middleware in the Use call short-circuits. I propose removing Run because it can cause Use calls to be skipped and there is no error to inform the programmer of this issue.
Motivation and goals
- Simplify the framework by reducing the number of methods that can be called
- Remove ambiguity as to which should be used
- Avoid silent pitfalls
Risks / unknowns
The risk is that is a breaking change, some might be using the Run call.
Examples
There are two ways to short-circuit:
By not calling next.Invoke()...
app.Use(async (context, next) =>
{
// Do something
// Don't call await next.Invoke();
});
And by calling app.Run instead of app.Use like so...
app.Run(async (context) =>
{
// Do something
});
Run is signalling to the programmer that no more pipeline elements will execute, whereas app.Use may or may not short-circuit. If Run is intended, why not just order the pipeline correctly so that the last item in the chain is the last item? The naming of Run is also ambiguous with the later call to Run which looks visually unappealing as if it were a bug when it isn't.