You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

async-didi

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-didi

Async Dependency Injection for JavaScript

0.3.1
latest
Source
npmnpm
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

async-didi

Build Status

An async version of didi, the tiny dependency injection container for JavaScript.

Example

import {
  AsyncInjector
} from 'async-didi';

function Car(engine) {
  this.start = function() {
    engine.start();
  };
}

async function createEngine(power) {
  return {
    start: function() {
      console.log('Starting engine with ' + power + 'hp');
    }
  };
}

const injector = new AsyncInjector([
  {
    'car': ['type', Car],
    'engine': ['factory', createEngine],
    'power': ['value', 1184]
  }
]);

await injector.invoke(async function(car) {
  await car.start();
});

For more examples, check out the tests.

Comparison to didi

  • Same core features
  • Exposes an AsyncInjector
  • Injector API functions get, invoke and instantiate are async
  • Factory functions may be async
  • No support for child injectors and scopes

License

MIT

Keywords

di

FAQs

Package last updated on 04 Nov 2021

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