Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created January 22, 2013 16:53
Show Gist options
  • Save groundwater/4596218 to your computer and use it in GitHub Desktop.
Save groundwater/4596218 to your computer and use it in GitHub Desktop.
// you can omit DI for _light_ dependencies
var async = require('async');
module.exports.inject = function( dependencies ){
// no direct require of _heavy_ dependencies
var mysql = dependencies.mysql;
var redis = dependencies.redis;
// do whatever
return // some presistence object
}
@groundwater
Copy link
Author

Each module in the application follows the same design.

Your server.js file can assemble the ensemble with:

var di = {}
di.mysql = require('./mysql').inject( di );
di.redis = require('./redis').inject( di );
di.app   = require('./app').inject( di );

// do something with di.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment