New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

di-kit

Package Overview
Dependencies
Maintainers
0
Versions
7
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

  • 1.0.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
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

FAQs

Package last updated on 16 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc