use method
Registers a middleware in this pipeline.
Middleware are executed in the order they are registered (first registered is outermost, wrapping all later middleware). This is the same behavior as popular web frameworks like Express.js.
Each middleware receives the next handler in the chain and must eventually call it (unless intentionally short-circuiting the chain).
Parameters:
middleware: The middleware function to add
Example:
pipeline.use((next) => (input) async {
print('Before');
final result = await next(input);
print('After');
return result;
});
Implementation
void use(Middleware<T> middleware) => _middlewares.add(middleware);