Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@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.js";
@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.js";
import {Calendar} from "./models/Calendar.js";
@Controller("/calendars")
export class CalendarCtrl {
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 is exposed 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, attachLogger} from "@tsed/di";
import {$log} from "@tsed/logger";
import {CalendarCtrl} from "./CalendarCtrl.js";
async function bootstrap() {
const injector = new InjectorService();
// configure the default logger
attachLogger(injector, $log);
// Load all providers registered via @Injectable decorator
await injector.load();
const calendarController = injector.get<CalendarCtrl>();
await calendarController.create(new Calendar());
// emit event to trigger actions for third parties modules
await injector.emit("$onReady");
// 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
,registerProvider
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 - 2022 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
The npm package @tsed/di receives a total of 5,914 weekly downloads. As such, @tsed/di popularity was classified as popular.
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.