0.3.1 • Published 3 years ago

async-didi v0.3.1

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

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

0.3.0

3 years ago

0.3.1

3 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago