Skip to content

Instantly share code, notes, and snippets.

@totherik
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totherik/fabf41557671067ac38e to your computer and use it in GitHub Desktop.
Save totherik/fabf41557671067ac38e to your computer and use it in GitHub Desktop.
DI Brainstorming
// Option 1: To be spec-ed
module.exports = function (router, obj1, obj2, obj3) {
// obj1
// obj2
// obj3
};
// Option 2: To be spec-ed. Counld behave similar to example below.
module.exports = function (router, context) {
// context.obj1
// context.obj2
// context.obj3
};
// Option 3: See config.js for config example.
module.exports = function (router, container) {
// container.resolve('obj1');
// container.resolve('obj2');
// container.resolve('obj3');
}
'use strict';
var http = require('http');
var express = require('express');
var enrouten = require('express-enrouten');
var app, server;
app = express();
app.use(enrouten({
"directory": "./routes",
"providers": {
"obj1": {
"depends": ["obj2"],
"$impl": function (obj2, cb) {
}
},
"obj2": {
"depends": [],
"$impl": function (cb) {
// Returned object is obj2 impl.
cb(null, {});
}
}
}
}));
server = http.createServer(app);
server.listen(8000);
'use strict';
var http = require('http');
var express = require('express');
var enrouten = require('express-enrouten');
var app, server;
app = express();
// Directory
app.use(enrouten({
"directory": "./routes",
"dependencies": ["config", "misc"],
"providers": {
"config": "config:",
"misc": {
"misc": "object"
}
}
}));
// Index
app.use(enrouten({
"index": "./routes",
"dependencies": ["config", "misc"],
"providers": {
"config": "config:",
"misc": {
"misc": "object"
}
}
}));
// Routes
app.use(enrouten({
"routes": [
{ path: '/', method: 'GET', handler: require('./routes/index'), dependencies: ["misc"] },
{ path: '/foo', method: 'GET', handler: require('./routes/foo') }
],
"dependencies": ["config", "misc"],
"providers": {
"config": "config:",
"misc": {
"misc": "object"
}
}
}));
server = http.createServer(app);
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment