Creates a "middleware provider", which is a middleware that can configure/extend the container before the application uses it.
class MyServiceWithMiddleware { constructor(private readonly responsesBuilder: ResponsesBuilder) {} getMiddleware() { return (_, res) => { this.responsesBuilder.json({ res, data: { message } }); }; } } const myMiddlewareProvider = middlewareProvider((app) => { app.set( 'myMiddleware', () => new MyServiceWithMiddleware(app.get('responsesBuilder')), ); return middleware(() => app.get<MyServiceWithMiddleware>('myMiddleware').getMiddleware(), ); }); Copy
class MyServiceWithMiddleware { constructor(private readonly responsesBuilder: ResponsesBuilder) {} getMiddleware() { return (_, res) => { this.responsesBuilder.json({ res, data: { message } }); }; } } const myMiddlewareProvider = middlewareProvider((app) => { app.set( 'myMiddleware', () => new MyServiceWithMiddleware(app.get('responsesBuilder')), ); return middleware(() => app.get<MyServiceWithMiddleware>('myMiddleware').getMiddleware(), ); });
A function that will be called the moment the application uses the middleware provider.
Creates a "middleware provider", which is a middleware that can configure/extend the container before the application uses it.
Example