This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/src/app/middleware/container_bindings_middleware.ts

19 lines
646 B
TypeScript
Raw Normal View History

2024-08-09 23:51:41 +02:00
import { HttpContext } from "@adonisjs/core/http"
import { Logger } from "@adonisjs/core/logger"
import type { NextFn } from "@adonisjs/core/types/http"
/**
* The container bindings middleware binds classes to their request specific value using the container resolver.
*
* - We bind "HttpContext" class to the "ctx" object.
* - And bind "Logger" class to the "ctx.logger" object.
*/
export default class ContainerBindingsMiddleware {
public async handle(ctx: HttpContext, next: NextFn): Promise<void> {
ctx.containerResolver.bindValue(HttpContext, ctx)
ctx.containerResolver.bindValue(Logger, ctx.logger)
return next()
}
}