Inject Param Decorator

With inject param decorator you inject a dependency into a class method as a parameter instead of as a class property.

Usage

Use the @injectParam() decorator to decorate a method parameter.

import { define, singleton, injectParam } from "@injex/core";
@define()
@singleton()
export class SomeService { ... }
@define()
@singleton()
export class SomeServiceProvider {
public getService(@injectParam() someService: SomeService) {
return someService;
}
}

Note that you can use the @injectParam() decorator in 3 ways just like the @inject() decorator:

  • Using auto-discovery dependency name:
    @injectParam() someService: SomeService
  • Using different name while providing the dependency name:
    @injectParam('someService') service: SomeService
  • Using different name while providing the dependency type:
    @injectParam(SomeService) service: SomeService

Caveats

  • Since the auto-discovery dependency name relies on the parameter name, this feature may not work when using code minifiers. If this is the case, you can choose one of the other options to decorate a method parameter.
  • @injectParam() decorators should be use to decorate the last parameters in the parameters list of a class method.

    For example:
    class SomeServiceProvider {
    public someMethod(p1: number, p2: string, @injectParam() s1, @injectParam() s2) {
    ...
    }
    }