Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@electron-tools/ioc
Advanced tools
A simple DI implement of IOC using typescript. inspired by vscode IOC implement.
# install by npm
$npm install @electron-toolkit/ioc
# install by pnpm
$pnpm add @electron-toolkit/ioc
# install by yarn
$yarn add @electron-toolkit/ioc
enable experimentalDecorators
option in your tsconfig.json.
register your service by service
decorator exported from this package.
// src/serviceA.ts
import { service } from '@electron-toolkit/ioc';
@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by this package.
class ServiceA {
// ....
}
inject
decorator inject your service to another service.// src/serviceB.ts
import { service, inject } from '@electron-toolkit/ioc';
@service('serviceB') // also register ServiceB with unique id 'serviceB'
class ServiceB {
constructor(
@inject('serviceA') // inject serviceA to serviceB, the only args passed to inject is the service unique id.
readonly serviceA: ServiceA,
)
}
// src/index.ts
import IOC from '@electron-toolkit/ioc';
import './serviceA.ts';
import './serviceB.ts';
const ioc = new IOC();
const serviceA = ioc.getService('serviceA');
const serviceB = ioc.getService('serviceB');
console.log(serviceA instanceof ServiceA); // true
console.log(serviceB instanceof ServiceA); // true
console.log(serviceA === serviceB.a); // true
ioc.getService('serviceA')
, serviceB will not be instance, cause serviceB is not dependencied by any service, but if you only call ioc.getService('serviceB')
, serviceA will be instance, and inject into serviceB. this maybe not what you want. you can init all services in one place by call ioc.init()
.const ioc = new IOC();
ioc.init(); // this statement will instance all services registered.
// src/serviceA.ts
import IOC, { service, inject } from '@electron-toolkit/ioc';
@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by ioc.
class ServiceA {
constructor(
@inject('instantiationService') readonly ioc: IOC, // ioc itself is also a service can be injected.
)
someMethod() {
// dynamic get serviceB by ioc#getService API. then you can do anything what serviceB can do.
const serviceB = this.ioc.getService('serviceB');
serviceB.xxx;
}
}
FAQs
DI implement of IOC
The npm package @electron-tools/ioc receives a total of 0 weekly downloads. As such, @electron-tools/ioc popularity was classified as not popular.
We found that @electron-tools/ioc 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.