🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

container-ioc

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

container-ioc

IoC container for browser and nodejs environments

1.0.7
Source
npm
Version published
Weekly downloads
129
148.08%
Maintainers
1
Weekly downloads
 
Created
Source

IoC Container in Typescript

API usage:

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:
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

FAQs

Package last updated on 14 Sep 2017

Did you know?

Socket

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.

Install

Related posts