Inversifyjs: Can't instantiate a class manually inside another class (ERROR_MSGS.NULL_ARGUMENT)

Created on 22 Feb 2018  路  1Comment  路  Source: inversify/InversifyJS

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

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

remojansen picture remojansen  路  4Comments

remojansen picture remojansen  路  4Comments

stjepangolemac picture stjepangolemac  路  5Comments

asykes74 picture asykes74  路  4Comments

Deviad picture Deviad  路  3Comments