GithubHelp home page GithubHelp logo

dipper's Introduction

Dipper.js

An lightweight promise-driven dependency injection library for Node.js. Heavily inspired by, and mostly compatible with, Cloud9's Architect.

Usage

A dipper-driven application is comprised of packages, each providing and consuming services.

Putting together an application consists of three simple steps:

  1. Application configuration. Divide logical modules into packages, each living in a separate directory, and list them in an application config file.
  2. Package configuration. Specify the services imported and exported from each package in tiny package config files. An entry point for each package is invoked with its imports, and a callback.
  3. Bootstrap the application. Give dipper.createApplication your application config.

In a bit more detail...

1. Application configuration

Packages are passed to dipper.createApplication, or set up in a JSON or Javascript configuration file โ€“ by default ./config.json โ€“ in the following manner:

{
  "packages": [
    "./some-package",
    {"path": "./another-package", "someParameter": "itsValue"}
  ]
}

The location of the config file can be set using the configFile option. The config can also be passed directly with the config option.

2. Package configuration

Each package requires a package.json in its root directory:

{
  "name": "Service 1", // optional (defaults to last part of package path)
  "main": "entry.js",  // the package's entry point (defaults to: name || 'index')
  "consumes": ["service2"], // package imports. must be provided by another package.
  "provides": ["service1"]  // package exports. can be consumed by other packages.
}

The package setup function

The entry point of each package must export a setup function, through which it is injected options, its dependencies, and a callback for registering its own provided services:

// A package entry point.
module.exports = function (options, imports, register) {
    var someServer = require('./someServer').setup(imports.service2);
    
    register(null, {
        service1: someServer
    });
};

Note that the register callback has a node-style error parameter as its first argument. Pass a falsy value to indicate success.

3. Bootstrap the application

Bring it all together. Finally, in your main application module:

var dipper = require('dipper');

dipper.createApplication(yourConfig).then(function (app) {
    app.services.service1.start();
})
.done();

API

@TODO.

dipper's People

Contributors

myrlund avatar

Watchers

 avatar  avatar

dipper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.