Created
October 10, 2011 04:05
-
-
Save domenic/1274607 to your computer and use it in GitHub Desktop.
Dependency injection sample with RequireJS
This file contains 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
// EntryPoint.js | |
define(function () { | |
return function EntryPoint(model1, model2) { | |
// stuff | |
}; | |
}); | |
// Model1.js | |
define(function () { | |
return function Model1() { | |
// stuff | |
}; | |
}); | |
// Model2.js | |
define(function () { | |
return function Model2(helper) { | |
// stuff | |
}; | |
}); | |
// Helper.js | |
define(function () { | |
return function Helper() { | |
// stuff | |
}; | |
}); | |
// composition root, probably your main module | |
define(function (require) { | |
var EntryPoint = require("./EntryPoint"); | |
var Model1 = require("./Model1"); | |
var Model2 = require("./Model2"); | |
var Helper = require("./Helper"); | |
var entryPoint = new EntryPoint(new Model1(), new Model2(new Helper())); | |
entryPoint.start(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From http://stackoverflow.com/questions/7708194#7708475