di-ioc
Dependency injection.
Installation
npm install --save di-ioc
Example
util/index.js
moduleexports = // Start defining a `random` service:;
app/index.js
moduleexports = // Greeting service which uses the random service: (arguments are detected);
index.js
moduleexports = ; var randomService = moduleexportsutilrandom; // eQ/NZnl7qusVN9hB/3nCn3wFKfY=console; // Hello World! Here is a random string: dfLGC20CpCJxAZSu+uFp57dlJl0=moduleexportsapp;
Features
- Export to a standard object which automatically initialises dependencies as needed. This is the object
.init()
creates. - Enforce that dependency graph divides into layers. For example, nothing in the 'util' submodule can depend on services in the 'app' submodule, due to the order of definition.
- Nest components in to hierarchial modules and folders.
- Instantiate one sub-tree of the hierarchy for testing.
- Instantiate objects with injected dependencies for unit testing.
- Define transient objects, using
require('di-ioc').create().transient('serviceName', ...);
.