Function middlewareProvider

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(),
);
});