InversifyJS
InversifyJS copied to clipboard
Missing required @inject or @multiInject - Inject in contructor is not wprking ( and hard to test) - dynamicvalue is a solution?
I could not inject into the constructor, only as private property ( React app)
I got this error:
or: Missing required @inject or @multiInject annotation in X: argument 0 in class
I see this issue here and I did not manage to fix it : https://github.com/inversify/InversifyJS/issues/1004
so I use the private property but this is very hard to test, i did not manage to test it with JEST
so I manage to create bind like that :
// Api service
container.bind<IApi>(TYPES.Api).toDynamicValue(() => {
const logger = container.get<ILogger>(TYPES.Logger);
const config = container.get<IConfig>(TYPES.ConfigService);
return new Api(config, logger);
});
and now in the API service, I can inject services in the constructor and then in jest I can just mock the constructor objects
is it a good solution ? is it still a singleton? what toDynamicValue is realy mean?
what is the difference between toDynamicValue to simple bind
problem still persists after 1 year