I'm not sure if I'm following the right approach here.
Basically I have to classes (ClassA, classB) and I'm trying to instantiate classA inside classB.
// inversify.js
import {ClassA} from './classA';
import {ClassB} from './classB';
inversifyContainer.bind<ClassA>(ClassA).toSelf();
inversifyContainer.bind<ClassB>(ClassB).toSelf();
// classB
method() { inversifyContainer.get<ClassA>(ClassA);
I got this error
/mnt/dati/Sorgenti/backend/backend-backend/node_modules/inversify/lib/container/lookup.js:13
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
^
Error: NULL argument
at Lookup.add (/mnt/dati/Sorgenti/backend/backend-backend/node_modules/inversify/lib/container/lookup.js:13:19)
at Container.bind (/mnt/dati/Sorgenti/backend/backend-backend/node_modules/inversify/lib/container/container.js:121:33)
at Object.<anonymous> (/mnt/dati/Sorgenti/backend/backend-backend/release/js/core/inversify.js:150:28)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
If I define ClassB inside inversify.ts rather than in a separate file, everything is working correctly.
using node 8.9.4, typescript 2.3.4 (tried with 2.7 too), last version of inversify
I managed to solve the issue. Basically in my entry point source (the script actually being run) I was importing some modules before loading the inversify.ts module and at the same time I was importing the "reflect-metadata" package in every module.
Removing the multiple metadata import and keeping the inversify.ts import at the beginning solves.
Most helpful comment
I managed to solve the issue. Basically in my entry point source (the script actually being run) I was importing some modules before loading the inversify.ts module and at the same time I was importing the "reflect-metadata" package in every module.
Removing the multiple metadata import and keeping the inversify.ts import at the beginning solves.