Just trying to get useContainer to work with inversify not injecting anything at the moment.
code looks like this:
index.ts
const app: express.Express = express();
useContainer(container);
useExpressServer(app, {
controllers: [__dirname + "/controllers/*.ts"],
});
container.ts
let container = new Container();
container
.bind<IController>(TYPES.ChangelogController)
.to(ChangelogController)
.whenTargetNamed("ChangelogController");
export { container }
Getting errors:
Error: No matching bindings found for serviceIdentifier: ChangelogController
Registered bindings:
ChangelogController - named: ChangelogController
at ActionMetadata.callMethod .../packages/..../src/metadata/ActionMetadata.ts:254:39)
at ..../packages/..../src/RoutingControllers.ts:123:142
I think you need to register your controllers in inversify framework since inversify requires all services to be registered in it. There were previous discussions on how to make it work and seems people do it.
@pleerock I registered the controller in inversify, but that seems to not help still getting the same error with ActionMetadata.callMethod I even logged out the container before and after useContainer and see the controller in there. Any Ideas?
updated comment above with new code and errors
Never-mind I got it to work by doing this:
container
.bind<IController>(ChangelogController)
.toSelf();
Looks like its solved
Yes I also got it to work using toSelf but everytime a call comes into my controller it creates an instance of it 2 times. I have placed a console.log inside the constructor and it is being called twice.
Yes I also got it to work using toSelf but everytime a call comes into my controller it creates an instance of it 2 times. I have placed a console.log inside the constructor and it is being called twice.
Hey, try to define the scope type:
const container = new Container();
container.bind<ControllerBase>(UserController).toSelf().inSingletonScope()
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.