Inversifyjs: Missing required @injectable annotation - but I'm pretty sure I have...

Created on 5 Apr 2017  路  4Comments  路  Source: inversify/InversifyJS

I have a class that helps with bindings that is getting called here: https://github.com/atrauzzi/protoculture/blob/master/demo/console.ts#L10-L17

The parent method it's using is here, which is where I call inversify: Which you can see here: https://github.com/atrauzzi/protoculture/blob/master/src/ServiceProvider.ts#L34-L37

All of this is orchestrated by this toplevel class, which does an import "reflect-metadata" here: https://github.com/atrauzzi/protoculture/blob/master/src/Suite/Base.ts#L1

But unfortunately, I still end up getting the following exception:

Error: Missing required @injectable annotation in: BoringConsoleDemoApp.
    at _createSubRequests (protoculture\node_modules\inversify\lib\planning\planner.js:107:19)
    at Object.plan (protoculture\node_modules\inversify\lib\planning\planner.js:126:5)
    at protoculture\node_modules\inversify\lib\container\container.js:228:37
    at Container._get (protoculture\node_modules\inversify\lib\container\container.js:221:44)
    at Container.getAll (protoculture\node_modules\inversify\lib\container\container.js:189:21)
    at ConsoleDemoSuite.BaseSuite.buildApps (protoculture\src\Suite\Base.ts:184:36)
    at ConsoleDemoSuite.<anonymous> (protoculture\src\Suite\Base.ts:140:18)
    at step (protoculture\src\Suite\Base.ts:31:23)
    at Object.next (protoculture\src\Suite\Base.ts:12:53)
    at fulfilled (protoculture\src\Suite\Base.ts:3:58)

Which is terrible, because I'm fairly certain I've done everything necessary to flag it as injectable. It's worth noting that if I do the annotation (which I'm trying to avoid), I get an error about applying the same annotation twice. A bit mysterious...

Most helpful comment

You need to decorate both the base and the derived class: BoringConsoleDemoApp extends BaseApp.
This means using injectable in BoringConsoleDemoApp and BaseApp. I'm not sure abut your makeInjectable function being invoked for BoringConsoleDemoApp and BaseApp?

The error:

Error: Missing required @injectable annotation in: BoringConsoleDemoApp.

Looks bad too me, Inversify should be able to tell you that the base class is missing the annotation.

Will check out to see if there is something wrong with the error generation.

All 4 comments

You need to decorate both the base and the derived class: BoringConsoleDemoApp extends BaseApp.
This means using injectable in BoringConsoleDemoApp and BaseApp. I'm not sure abut your makeInjectable function being invoked for BoringConsoleDemoApp and BaseApp?

The error:

Error: Missing required @injectable annotation in: BoringConsoleDemoApp.

Looks bad too me, Inversify should be able to tell you that the base class is missing the annotation.

Will check out to see if there is something wrong with the error generation.

Yup, that worked!

https://github.com/atrauzzi/protoculture/blob/master/src/Suite/ProtocultureServiceProvider.ts#L10

I definitely agree, some mention of _"hey, it's actually your abstract class that I don't know about"_ would be useful in this case.

I though that was the way the error worked. I must check it out. Will leave this issue open until I find out.

Closing this issue because I have created an issue that makes more clear how to reproduce the issue.

Was this page helpful?
0 / 5 - 0 ratings