jeffijoe / awilix-express

Awilix helpers/middleware for Express
MIT License
118 stars 7 forks source link

Resloving dependencies inside @before #27

Closed heilmela closed 4 years ago

heilmela commented 4 years ago

As mentioned in the doc i have to import the middleware... Well is it possible to inject the middleware as follows after registering it to the DI container:

  //inside route handler
  @route('/')
  @GET()
  @before([{ middleware }])
  async findMe(req, res) {

Furthermore even if i import the middleware and pass it to @before, inside the middleware function no dependency is resolved. middleware.js:

export default function middleware({ tokenService }) { 
  //tokenService is unedefined by the time @before invokes the middleware (when receiving a request)
  //while in my route handler it is resolved as expected
}

How do i deal with middleware which has dependencies if none of the above works as i would expect it ? Is this intended ?

heilmela commented 4 years ago

Duplicate https://github.com/talyssonoc/awilix-express/issues/22#issue-512483270