
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
container-ioc
Advanced tools
import { Container, Inject } from 'container-ioc';
let container = new Container();
// Register classes:
class RandomClass1 {};
class RandomClass3 {
doSomething(): void {
console.log('hello world');
}
};
// Use Injector decorater to inject dependencies:
class RandomClass2 {
constructor(@Inject(RandomClass3) public instance3: any) {
}
};
// Register classes in the container:
// You can pass just a Class literal alone or a provider literal ->
// { token: 'string or class literal', useClass: 'class literal' }
let providers = [
RandomClass1,
{ token: 'anystring', useClass: RandomClass2 },
{ token: RandomClass3, useClass: RandomClass3 }
];
container.register(providers);
// Resolve instances
let instance1: RandomClass1 = container.resolve(RandomClass1);
let instance2: RandomClass2 = container.resolve('anystring');
instance2.instance3.doSomething(); // hello world
let Container = require('container-ioc').Container;
let container = new Container();
// Register classes:
class RandomClass1 {};
class RandomClass3 {
doSomething() {
console.log('hello world');
}
};
// Use Injector decorater to inject dependencies:
class RandomClass2 {
instance3;
constructor() {
this.instance3 = container.resolve(RandomClass3);
}
};
// Register classes in the container:
// You can pass just a Class literal alone or a provider literal ->
// { token: 'string or class literal', useClass: 'class literal' }
let providers = [
RandomClass1,
{ token: 'anystring', useClass: RandomClass2 },
{ token: RandomClass3, useClass: RandomClass3 }
];
container.register(providers);
// Resolve instances
let instance1 = container.resolve(RandomClass1);
let instance2 = container.resolve('anystring');
instance2.instance3.doSomething(); // hello world
if a provider wasn't found in a container it will look up in ascendant containers if there's any:
import { Container } from 'container-ioc';
class SomeClass {
doStuff(): void {
console.log('hello world');
}
}
let parentContainer = new Container();
let childContainer = parentContainer.createScope();
parentContainer.register({ token: 'ISome', useClass: SomeClass });
childContainer.resolve('ISome');
let instance = childContainer.resolve('ISome');
instance.doStuff(); // hello world
FAQs
Dependency Injection and Inversion of Control (IoC) container
The npm package container-ioc receives a total of 62 weekly downloads. As such, container-ioc popularity was classified as not popular.
We found that container-ioc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.