Last active
August 29, 2015 14:10
-
-
Save totherik/fabf41557671067ac38e to your computer and use it in GitHub Desktop.
DI Brainstorming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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