This would be interesting:
app.UseWhenElse(
context => context.condition(),
applicationBuilder => { /* Condition is true */ },
applicationBuilder => { /* Condition is false */ }
});
This would allow me to do conditional routing based and handle both branches in one middleware thingie. But it doesn't exist. So I have to use this ugly construction:
app.UseWhen(
context => context.condition(),
applicationBuilder => { /* Condition is true */ }
});
app.UseWhen(
context => !context.condition(),
applicationBuilder => { /* Condition is false */ }
});
Now, the problem is that context.condition() gets called twice here, and this is a method, not a value. I don't want this method to execute twice so I'm considering writing an UseWhenElse() myself. But am I reinventing the wheel?