Open tariano opened 4 years ago
请问你解决了么?
In case anyone stumbles upon this: This is seems not to be an issue with the library itself, but with the way code is compiled and then evaluated during run time.
tariano's main.ts
does not include any import of the Katana
class or refererence to the weapon.ts
file in general, which makes sense since it's supposed to be injected. However, this means the run time will execute the code in main.ts
without ever touching Katana
(as only the Weapon
interface is referenced by the Ninja
class) and thus it's provide
decorator is never evaluated.
Unfortunately, there seems no real fix to this. Only the workaround of explicitly importing the module like so:
import './src/weapon';
... at the beginning of main.ts
, in order to ensure the class is bound to the container before accessing it.
Still, I hope this helps!
Expected Behavior
I expect to see
success
emitted to console in code belowCurrent Behavior
Instead, I see the error
Error: No matching bindings found for serviceIdentifier: Weapon
Steps to Reproduce (for bugs)
Just run the snippet below
Context
I'm trying to use
inversify-binding-decorators
to get rid of boilerplate.Your Environment
"inversify": "^5.0.1"
,"inversify-binding-decorators": "^4.0.0"
,"reflect-metadata": "^0.1.13"
Detailed description:
The following code was working very well, until I separated it to different files:
After refactoring, this is the new file structure:
They hold the same logic, just separated:
warrior.ts:
weapon.ts:
main.ts:
But now it fails on
const ninja = container.get(Ninja);
with errorError: No matching bindings found for serviceIdentifier: Weapon
.