saskodh / framework

Lightweight web framework for NodeJS inspired by Spring framework
26 stars 5 forks source link

Injecting by reference token is broken #1

Closed draganAndonovski closed 8 years ago

draganAndonovski commented 8 years ago

Description

The injector should allow injecting dependencies by reference token. The reference token is provided in the @Component decorator. This is broken at the moment. Example:

const BReferenceToken = Symbol('B-Reference-Token');
@Component(BReferenceToken)
class B { }

@Component()
class A {
  @Inject(BReferenceToken)
  private dependency: B;
}

When running the given code we received this error:

Loading dynamically by @ComponentScan: GreetingsController.js (C:\data\showcase\framework-showcase\src\app\controllers\GreetingsController.js)
C:\data\framework\dist\src\lib\decorators\InjectionDecorators.js:14
            throw new Error('Cannot inject dependency which is not a @Component!');
            ^

Error: Cannot inject dependency which is not a @Component!
    at exports.Inject (C:\data\framework\dist\src\lib\decorators\InjectionDecorators.js:14:19)
    at __decorate (C:\data\showcase\framework-showcase\src\app\controllers\GreetingsController.js:5:110)
    at Object.<anonymous> (C:\data\showcase\framework-showcase\src\app\controllers\GreetingsController.js:58:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)

Process finished with exit code 1
saskodh commented 8 years ago

Fixed the issue and added support for injecting by property type. @draganAndonovski please verify.