Ghost is simple dependency injection manager. It is easy to use and avaliable in node.js and browser. No dependencies are needed.
Installation
$ npm install ghost-inject
Usage
Initialization
Ghost = injector = ;
Adding services
anyService = a: 10; injector;
Adding factories
Factories are lazy loaded services. Once the service is created by the factory, it is saved and returned each time.
{ return connected: true ;}; injector;
Calling functions with dependencies
{ // database is injected here if service or factory was provided before}; injector
Injecting functions
{ // database is injected here if service or factory was provided before}; // injector will return function with bound argumentsbound = injector;; // call injected function
both
call
andinject
can be provided with this parameter as a second parameter. Also additional dependency list can be provided for local dependencies.
if collision occurs within specified list and service in the injector, service from the list will be used
Creating instances
{ thispeople = people; thishandbreak = true;}; myCar = injector;
people
argument will here be injected into constructor if service calledpeople
was previously defined
Resolving dependencies
{}; deps = injector;// deps is now array containing arguments for the given function
Getting function arguments
{}; deps = injector// deps = ['a', 'b', 'c']