Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including kantaina with all npm packages installed. Try it out:

var kantaina = require("kantaina")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

kantaina v1.1.8

Wonderful asynchronous DI container based on promises.

kantaina

Wonderful asynchronous DI container based on promises.

Build Status Coverage Status Dependency Status NPM version

Usage

kantaina = require "kantaina"
w = require "when"

# create container
container = kantaina()

# define scalar value
container.set "a", 1

# define sync factory
container.set "b", (a) ->
  a + 1

# define async factory
container.set "c", (a, b) ->
  deffered = w.defer()

  setTimeout ->
    deffered.resolve a + b
  , 1000

  deffered.promise

# try to override already defined value
container.unless "a", 100

# receive value resolved by async factory
container.get("c").then (value) ->
  # writes "3" after one second
  console.log value

# inject dependencies into function
promise = container.inject (a, b, c) ->
  a + b + c

# inject method returns promise
promise.then (value) ->
  # writes "6" immediately because "c" already resolved
  console.log value
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free