Skip to content
Symfony2 inspired dipendency injection container in pure JavaScript
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
LICENSE
README.md
bower.json
dicon-min.js Initial release 0.1.0
dicon.js
package.json
release.js

README.md

dicon.js

Symfony2 inspired dipendency injection container in pure JavaScript.

License: MIT

Example Usage

// define a dummy hello world service
var Acme = function (name) {
  if (name) {
    this.sayHello(name);
  }
};
Acme.prototype.sayHello = function (name) {
  console.log('Hello ' + name + '!');
};

// define some initial parameters to start with
var someParameters = {
  username: "sweikenb"
};

// create the dependency container (if you don't have initial parameters just skipp the arument)
var container = new Dicon(someParameters);

// add a new parameter "on-the-fly"
container.setParameter('repository', "https://github.com/sweikenb/dicon.js");

// register the acme service and add the "username"-parameter as dependency
container.register('acme', Acme, ['%username%']);

// define a service "on-the-fly" and add the "acme"-service and the container itself as dependency
container.register('helloWorld', function (acme, container) {
  acme.sayHello('World, please have a look at: '+container.getParameter('repository'));
}, ['acme', '&']);


// HINT: if you like to inject the container itself as an dependency use the special '&' service-id.


// request the services
var greeter = container.get('acme');
container.get('helloWorld');

// call a service method
greeter.sayHello('Octocat');

This will return:

Hello sweikenb!
Hello World, please have a look at: https://github.com/sweikenb/dicon.js!
Hello Octocat!
Something went wrong with that request. Please try again.