Generates a configurable middleware provider for the application to use. This is a mix of a middleware creator and a middleware provider: it gives you the flexibility of the creator, with the resources of the provider.
class MyServiceWithMiddleware { constructor(private readonly responsesBuilder: ResponsesBuilder) {} getMiddleware() { return (_, res) => { this.responsesBuilder.json({ res, data: { message } }); }; } } const myMiddlewareProvider = middlewareProviderCreator( ({ serviceName = 'myMiddleware' }) => (app) => { app.set( serviceName, () => new MyServiceWithMiddleware(app.get('responsesBuilder')), ); return middleware(() => app.get<MyServiceWithMiddleware>(serviceName).getMiddleware(), ); }, ); // ... container.use(myMiddlewareProvider); Copy
class MyServiceWithMiddleware { constructor(private readonly responsesBuilder: ResponsesBuilder) {} getMiddleware() { return (_, res) => { this.responsesBuilder.json({ res, data: { message } }); }; } } const myMiddlewareProvider = middlewareProviderCreator( ({ serviceName = 'myMiddleware' }) => (app) => { app.set( serviceName, () => new MyServiceWithMiddleware(app.get('responsesBuilder')), ); return middleware(() => app.get<MyServiceWithMiddleware>(serviceName).getMiddleware(), ); }, ); // ... container.use(myMiddlewareProvider);
container.use(myMiddlewareProvider({ serviceName: 'something' })); Copy
container.use(myMiddlewareProvider({ serviceName: 'something' }));
A function that will generate a middleware provider.
Generates a configurable middleware provider for the application to use. This is a mix of a middleware creator and a middleware provider: it gives you the flexibility of the creator, with the resources of the provider.
Example: Basic usage
Example: Custom parameters