Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@decorators/di
Advanced tools
npm install @decorators/di --save
Fully working example can be found in example folder.
@Injectable()
- Registers class as provider in the container@Injectable()
class HttpService {}
@Inject(injectable: Injectable)
- A parameter decorator that marks parameter as dependency.@Injectable()
class HttpService {
constructor(@Inject(API_URL) apiUrl: string) {}
}
@Optional()
- A parameter decorator that marks parameter as optional dependency.@Injectable()
class HttpService {
constructor(@Optional() @Inject(API_URL) apiUrl: string) {}
}
InjectionToken
- Creates a token that can be used in DI as Provider.const API_URL = new InjectionToken('API_URL');
...
@Injectable()
class HttpService {
constructor(@Inject(API_URL) apiUrl: string) {}
}
Container
- Container interface
.setParent(container: Container)
- set parent container.provide(providers: Providers[])
- Registers an array of providers..get<T>(injectable: Injectable): Promise<T>
- Retrieves a Promise with an instance of the injectable, throws:
MissingProviderError
if dependency provider wasn't foundRecursiveProviderError
in case of recursive dependency injectionconst container = new Container();
container.provide([
{
provide: 'Message',
async useFactory() {
return delay('Async Provider');
},
},
{
provide: 'Hello World',
useClass: Service,
},
]);
It's possible to provide multiple things using one injection token via multi
flag:
container.provide([
{
provide: GLOBAL_PIPE,
useClass: ServerPipe,
multi: true
},
{
provide: GLOBAL_PIPE,
useClass: ErrorPipe,
multi: true
},
]);
FAQs
node decorators - decorators for dependency injection
The npm package @decorators/di receives a total of 1,698 weekly downloads. As such, @decorators/di popularity was classified as popular.
We found that @decorators/di demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.