Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@tsed/di
Advanced tools
A package of Ts.ED framework. See website: https://tsed.io/
You can get the latest release and the type definitions using npm:
npm install --save @tsed/di
Important! TsExpressDecorators requires Node >= 6, Express >= 4, TypeScript >= 2.0 and the
experimentalDecorators
,emitDecoratorMetadata
,types
andlib
compilation options in yourtsconfig.json
file.
{
"compilerOptions": {
"target": "es2016",
"lib": ["es2016"],
"typeRoots": [
"./node_modules/@types"
],
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators":true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
}
Basically, almost everything may be considered as a provider – service, factory, intereceptors, and so on.
All of them can inject dependencies, meaning, they can create various relationships with each other.
But in fact, a provider is nothing else than just a simple class annotated with an @Injectable()
decorator.
Here is a basic usage to declare an injectable service to another one:
import {Injectable} from "@tsed/di";
import {Calendar} from "./models/calendar";
@Injectable()
export class CalendarsService {
private readonly calendars: Calendar[] = [];
create(calendar: Calendar) {
this.calendars.push(calendar);
}
findAll(): Calendar[] {
return this.calendars;
}
}
Here's a CalendarsService, a basic class with one property and two methods. The only new trait is that it uses the @Injectable()
decorator.
The @Injectable()
attaches the metadata, thereby Ts.ED knows that this class is a provider.
Now we have the service class already done, let's use it inside a controller:
import { Controller, Post, Body, Get } from '@tsed/common';
import { CalendarsService } from './CalendarsService';
import { Calendar } from './models/Calendar';
@Controller('/calendars')
export class CalendarService {
constructor(private readonly calendarsService: CalendarsService) {}
@Post()
async create(@Body() calendar: Calendar) {
this.calendarsService.create(calendar);
}
@Get()
async findAll(): Promise<Calendar[]> {
return this.calendarsService.findAll();
}
}
Note: Controller isn't a part of
@tsed/di
.@Controller
decorator are defined by@tsed/common
package because it's a specific provider used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
Finally, we can load the injector and use:
import {InjectorService} from "@tsed/di";
import {CalendarCtrl} from "./CalendarCtrl";
async function bootstrap() {
const injector = new InjectorService()
// Load all providers registered via @Injectable decorator
await injector.load()
const calendarController = injector.get<CalendarCtrl>()
await calendarController.create(new Calendar())
// And finally destroy injector and his instances (see injector hooks)
await injector.destroy()
}
bootstrap()
To organize your code Ts.ED DI provide different kind of providers:
@Injectable
,@Service
,@Interceptor
,registerFactory
and registerValue
.See more details on our documentation https://tsed.io/providers.html
Please read contributing guidelines here
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
The MIT License (MIT)
Copyright (c) 2016 - 2018 Romain Lenzotti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
DI module for Ts.ED Framework
We found that @tsed/di demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.