microsoft / tsyringe

Lightweight dependency injection container for JavaScript/TypeScript
MIT License
5.18k stars 172 forks source link

A way to add custom properties to the controller #238

Closed SwagiWagi closed 7 months ago

SwagiWagi commented 7 months ago

Description I want to be able to have middleware add custom parameters to my controller, for example:

const addCustomParamMiddleware = (req: express.Request, res: express.Response, next: nextFuncType) => {
  req.locals.tsoaCustomParams = {
    requestId: req.headers["x-request-id"]
  }

  next();
}

@middlwares(addCustomParamMiddleware)
@Get("{screenName}/details")
  public async details(@Path() screenName: string, @CustomParam("requestId") requestId: string): Promise<any> {
    //logic
  }
}

app.use(addCustomParamMiddleware);
registerRoutes(app);
SwagiWagi commented 7 months ago

Mistake in repo