-
-
+
+
@@ -103,7 +86,7 @@
-
+
@@ -113,23 +96,33 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -176,18 +169,19 @@
-
-
+
+
+
-
-
+
+
@@ -373,14 +367,14 @@
-
+
-
+
@@ -388,11 +382,11 @@
-
+
-
+
@@ -511,11 +505,7 @@
-
-
-
-
-
+
@@ -561,11 +551,7 @@
-
-
-
-
-
+
@@ -603,11 +589,7 @@
-
-
-
-
-
+
@@ -645,11 +627,7 @@
-
-
-
-
-
+
@@ -680,11 +658,7 @@
-
-
-
-
-
+
@@ -707,11 +681,7 @@
-
-
-
-
-
+
@@ -741,7 +711,6 @@
-
@@ -761,22 +730,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -793,45 +746,62 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/app.js b/app/app.js
index 5416ff0..f7b33db 100644
--- a/app/app.js
+++ b/app/app.js
@@ -1,4 +1,4 @@
-(function (should, commandr, bindr) {
+(function (should, commandr, bindr, Container) {
var app = {
views: {}
@@ -9,6 +9,8 @@
var commandHandlers = {};
var runObservers = [];
+ app.di = new Container();
+
function resolveOrInject(name, inst, container, entityName) {
var resolved;
@@ -66,4 +68,4 @@
-})(window.should, window.commandr, window.bindr);
\ No newline at end of file
+})(window.should, window.commandr, window.bindr, window.Container);
\ No newline at end of file
diff --git a/components/container.js b/components/container.js
new file mode 100644
index 0000000..39888ac
--- /dev/null
+++ b/components/container.js
@@ -0,0 +1,40 @@
+(function(should){
+ function Container(store) {
+ this.store = {};
+ this.resolved = {};
+ }
+
+ Container.prototype.register = function(name, inst) {
+ var reg = this.store[name];
+ if(reg == null) {
+ reg = this.store[name] = { instance: inst };
+ }
+ return reg;
+ };
+
+ Container.prototype.resolve = function(name) {
+ var reg = this.store[name];
+ if(reg == null) {
+ throw new Error(''); // TODO: wrote
+ }
+
+ if(reg.resolved == null) {
+ var inst = reg.instance;
+ this.resolveProperties(inst);
+ reg.resolved = inst;
+ }
+
+ return reg.resolved;
+ };
+
+ Container.prototype.resolveProperties = function (instance) {
+ for(var property in instance) {
+ if(property[0] == '$') {
+ var name = property.substr(1, property.length - 1);
+ instance[property] = this.resolve(name);
+ }
+ }
+ };
+
+ window.Container = Container;
+})();
diff --git a/index.html b/index.html
index 7f58a60..4563ad8 100644
--- a/index.html
+++ b/index.html
@@ -9,6 +9,7 @@
+
@@ -26,13 +27,6 @@
-
-
-
@@ -99,6 +93,18 @@
cmdArgs.commandHandled = true;
});
+ app.di.register("ts", {
+ $html:null,
+ doStuff: function() {
+ console.log(this.$html);
+ }
+ });
+
+ app.di.register('html', { he: 23});
+
+ var t = app.di.resolve('ts');
+ t.doStuff();
+
app.bootstrap(document.getElementById('rootView'));
})();