Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

di-kit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

di-kit

Minimal ioc container which allow circular dependency injection

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

di-kit

Minimal ioc container which allow circular dependency injection

Installation

npm install di-kit

Code sample

import { inject, provide, init } from './index.mjs';

const TYPES = {
    serviceFoo: Symbol('serviceFoo'),
    serviceBar: Symbol('serviceBar'),
    serviceBaz: Symbol('serviceBaz'),
};

provide(
    TYPES.serviceFoo, 
    () => new class {
        bar = inject(TYPES.serviceBar);
    }
);

provide(
    TYPES.serviceBar,
    () => new class {
        foo = inject(TYPES.serviceFoo);
        baz = inject(TYPES.serviceBaz);
    }
);

provide(
    TYPES.serviceBaz,
    () => new class { }
);

const ioc = {
    serviceFoo: inject(TYPES.serviceFoo),
    serviceBar: inject(TYPES.serviceBar),
    serviceBaz: inject(TYPES.serviceBaz),
};

init();

console.log(ioc.serviceFoo.bar.name);
console.log(ioc.serviceBar.foo.name);
console.log(ioc.serviceBar.baz.name);

See also

If you looking for ASP.Net Core Scoped Services alternative for NodeJS take a look on di-scoped npm package


import { scoped } from 'di-scoped';

const TestClass = scoped(class {

    constructor(private name: string) {
    }

    test() {
        console.log(`Hello, ${this.name}`);
    }
});


TestClass.runInContext(() => {

    new TestClass().test(); // Hello, Peter

}, "Peter")

Keywords

nodejs

FAQs

Package last updated on 27 Feb 2026

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