jeffijoe / awilix-express

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

build: expected targetOrResolver to be a function or class, but got '...' #23

Closed jfbelisle closed 3 years ago

jfbelisle commented 4 years ago

Hi,

I'm trying to inject my middleware function as per your example, https://github.com/talyssonoc/node-api-boilerplate/blob/adce807fdd36ac86a44965d0327ec06b9e803225/src/interfaces/http/user/UsersController.js

But I get this error message": "build: expected targetOrResolver to be a function or class, but got. ....",

This is how I registered it

// Operations
container.register({
  getAllEmplois: asClass(GetAllEmplois),
  getEmploi: asClass(GetEmploi),
});

And in my controller:

get router() {
    const router = Router();

    router.get('/', inject('getAllEmplois'), this.all);
    router.get('/:id', inject('getEmploi'), this.one);

    return router;
  }

Am I missing something?

Thank you

jeffijoe commented 4 years ago

That’s the old signature, please check the docs for inject usage

jfbelisle commented 4 years ago

Ok, but if I do it this way:

router.get('/', inject(({ getAllEmplois }) => this.all));

all(req, res, next) {
    const { getAllEmplois } = req;
    const { SUCCESS, ERROR } = getAllEmplois.outputs;
...

getAllEmplois doesn't get resolved

jeffijoe commented 4 years ago

Inject no longer sets anything on req. Use the factory function to return an inline handler and capture the dependency.