express-resource-new
express-resource-new copied to clipboard
Bind the controller to each resource-callback to allow passing a class i...
...nstance as a controller.
This patch allows passing a class-instance as a controller. Consider the following pseudocode as an example:
Controller.js:
function Controller(Model) {
this.Model = Model;
}
Controller.prototype.index = function(req, res, next) {
this.Model.find(function(err, entries) {
if (err) return next(err);
res.send(entries);
}
}
then in controllers/users/index.js:
var Controller = require('../Controller.js');
module.exports = (function() { return new Controller(UserModel) })();
Personally I have my own controller initialization logic and I overwrite the app._load() method to inject my controller instances.
Let me know what you think!
:+1: