-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing required @injectable annotation in ThirdPartyClass
#297
Comments
You can invoke the decorator using the decorate function:
Check out https://github.com/inversify/InversifyJS/blob/master/wiki/basic_js_example.md for more info. |
Thanks for the hint. This solution resolves my issue. But I have a follow up question which is more about how to solve the problem with third party dependency in the most elegant way. Assuming my class from above needs to call the I cannot use any of the work arounds mention in the inheritance article, as all of these need to modify the base class. In my case its a NodeJS Stream wich must get the config object in the constructor. My current solution to this problem is, to inject the config for the base class into my own class and then pass it to the base class, which means that I need to register the config in my kernel, which would basically not be necessary as it could be hard coded. Both solutions work, but seem far from perfect. Solution 1: decorate(injectable(), PassThrough);
@injectable()
class Dependency extends PassThrough {
constructor(@inject('objectModeConfig') private config: any) {
super(config);
}
}
kernel.bind('Dependency').to(Dependency);
kernel.bind('objectModeConfig').toConstantValue({ objectMode: true }); Solution 2: decorate(injectable(), PassThrough);
@injectable()
class Dependency extends PassThrough {
constructor(@inject('dummy') private dummy: any) {
super({ objectMode: true });
}
}
kernel.bind('Dependency').to(Dependency);
kernel.bind('dummy').toConstantValue('dummy'); |
I will do something to improve this. About your problem I think option 1 is better. I would recommend to use option one and inject the config as a constant value: kernel.bind<any>("config").toConstantValue({ objectMode: true }); I will also try to think more about it and see If I add a better solution to the docs. |
Hi @lukas-zech-software the next release will include a new workaround for your issue #333 |
@remojansen will the
and another class in another package using inversify/
|
@mrfoh did you get the solution? I am facing the same issue. |
@mrfoh me too :( |
Aww, I guess this issue was never solved before the project was abandoned :'( |
Poor us |
Container option |
I have a class MyStream that extends the NodeJS.PassThrough stream class.
This class should be injected as dependency in another class called Consumer
Consumer and MyStream are both marked with
@injectable
and bound to the kernelTrying to resolve MyStream fails with the message
Missing required @injectable annotation in: PassThrough
As PassThrough is not my own code, I cannot put the decorator on it.
I read through the issues and documentation but could not find a solution to this problem.
Two mentions are similiar, yet I could not adept the solution from there:
#262: In this the user seems to have loaded two different node modules, both under his ownership. Both modules imported
reflect-metadata
causing theReflect
singleton to be overwritten. In my case, only my own library importsreflect-metadata
, the other module being the NodeJS API obviously does not loadReflect
itself (I use NodeJs 5.7.0, no Reflect implemented there)Inheritance Doc: It is mentioned here, that there are problems when injecting dependencies in the base class, if the constructor and super constructor have different parameter count.
This also does not seems to apply to my situation. I tried the mentioned workaround B nonetheless and injected the dependency in a property instead of the constructor, which yielded the same Error.
So my question is:
How can I resolve a dependency that itself extends a third party type?
Your Environment
The text was updated successfully, but these errors were encountered: