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.
inject.min
Advanced tools
npm i inject.min --save
modify your tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true
}
}
import { DIContainer, Inject } from 'inject.min';
class Example {
value: string;
constructor(props?: { param: string }) {
this.value = props?.param || 'example';
}
}
class Example2 extends Example {
constructor(param: string) {
super({ param });
}
}
class Test {
@Inject(Example) example!: Example;
@Inject(Example2, 'example2') example2!: Example2;
@Inject(Example, { param: 'example3' }) example3!: Example;
constructor() {
console.log(this.example.value); // example
console.log(this.example2.value); // example2
console.log(this.example3.value); // example3
}
}
class Test2 {
@Inject(Example) example!: Example;
@Inject(Example2, 'different') example2!: Example2;
@Inject(Example, { param: 'example3' }) example3!: Example;
constructor() {
console.log(this.example.value); // example
console.log(this.example2.value); // different
console.log(this.example3.value); // example3
}
}
class Test3 extends Test {}
const test = new Test(); // example, example2, example3
const test2 = new Test2(); // example, different, example3
const test3 = new Test3(); // example, example2, example3
console.log(test.example === test2.example); // true
console.log(test.example2 === test2.example2); // false
console.log(test.example2 === test3.example2); // true
// override
class Original {
name = 'original';
}
class Override extends Original {
name = 'override';
}
class TestOverride {
@Inject(Original) test!: Original;
constructor() {
DIContainer.bind(Original, Override);
console.log(this.test.name);
}
}
new TestOverride(); // override
MIT
FAQs
lightweight typescript dependency injection in 2024
We found that inject.min 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
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.