build: expected targetOrResolver to be a function or class, but got '...'
jfbelisle opened this issue · comments
JF Bélisle commented
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
Jeff Hansen commented
That’s the old signature, please check the docs for inject usage
JF Bélisle commented
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
Jeff Hansen commented
Inject no longer sets anything on req. Use the factory function to return an inline handler and capture the dependency.