npm.io
1.0.2 • Published 5 years ago

@prats-tech/nestjs-static-injector

Licence
MIT
Version
1.0.2
Deps
3
Size
8 kB
Vulns
3
Weekly
0
Stars
1

rx-channels

NestJS Static Injector - v1.0.0


Overview

This library solves a framework weakness of not having to statically access providers in the application, something that can be commonly used in decorators, as decorators are executed in the application compilation process and not during the code interpretation, that is, you cannot access providers by instance, this is one of the reasons for the existence of this library.

Installation

# Using NPM
$ npm install @prats-tech/nestjs-static-injector

---

# Using Yarn
$ yarn add @prats-tech/nestjs-static-injector
Examples/Reasons
import { Module, MyService } from '@nestjs/common';

import { StaticModule } from '@prats-tech/nestjs-static-injector';

@Module({
  imports: [StaticModule],
  providers: [MyService],
  exports: [MyService],
})
class AppModule {}

@Injectable()
class MyService {
  execute() {
    // execute some logic
  }
}

function Decorator() {
  return function (target: any) {
    const service = StaticInjector.getInstance().get(MyService);
    service.execute();
  };
}

@Decorator()
class ClassThatWillUseTheDecorator {}

License

MIT Prats

Keywords