ecowden / pluto.js

JavaScript Dependency Injection
MIT License
8 stars 3 forks source link

Asynchronous Injection #25

Closed ecowden closed 7 years ago

ecowden commented 7 years ago

Pluto should support asynchronous bootstrapping by automatically detecting and resolving promises, then injecting their resolved values when used as a dependency.

Sample usage:

  function Greeter(name) {
    this.name = name
  }

  Greeter.prototype.greet = function () {
    return `Hello, ${this.name}!`
  }

  const bind = pluto()
  bind('name').toInstance(Promise.resolve('World'))
  bind('greeter').toConstructor(Greeter)

  const theGreeter = yield bind.get('greeter')

  t.is(theGreeter.greet(), 'Hello, World!')
ecowden commented 7 years ago

Fixed on one-oh-redesign branch.