2

i have this error

Unhandled error in POST /client: 500 Error: The key 'controllers.pointController' is not bound to any value in context application

My class

constructor(
        @repository(ClientRepository)
        public clientRepository: ClientRepository,           
        // Controllers            
        @inject('controllers.pointController')
        public pointController: PointController,

    ) {
    }
// functions

i follow the documentarion of loopback4 and dependency injection, but doesn't work

any idea?

h40s4m4
  • 170
  • 1
  • 14

1 Answers1

3

By default, LoopBack uses PascalCase keys when binding controller classes, see e.g. this test:

https://github.com/strongloop/loopback-next/blob/0444120cda7119c66bc2170f4817e67d8dc9d312/packages/core/src/tests/unit/application.unit.ts#L25-L33

expect(binding.key).to.equal('controllers.MyController');

Your example does not provide enough information, so I'll assume your controller is defined as a class PointController in src/controllers/point.controller.ts file and you are using @loopback/boot to load and register your application's artifacts.

In that case, you need to fix your code as follows - notice the upper-case P:

@inject('controllers.PointController')

Additional information

In the future, you can use debug logs to find binding keys created for the different artifacts. On Unix (MacOS, Linux):

DEBUG=loopback:context:binding npm start

In the debug log, you should see a message like this:

loopback:context:binding Bind controllers.PointController to class PointController

The part controllers.PointController is the binding key to use for @inject, the part PointController is the name of the controller class.

Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99