(function(app, should, Container) { var controllerDi = app.di; // TODO: Compbine app.controller = function(name, instOrFactory) { should.beString(name, "name"); if(instOrFactory == null) { return controllerDi.resolve(name); } var reg = new Container.Registration(instOrFactory); reg.onFirstTimeResolve = function (inst) { addControllerMixin(inst); }; controllerDi.register(name, reg); }; function addControllerMixin(ctrl) { ctrl.attachView = function(viewElement) { this.viewElement = viewElement; if(typeof ctrl.onViewAttached == 'function') { ctrl.onViewAttached(viewElement); } }; ctrl.detachView = function() { this.viewElement = null; if(typeof ctrl.onViewDetached == 'function') { ctrl.onViewDetached(viewElement); } }; } app.run(function(){ attachControllers(app.rootViewElement, app.di); }); function attachControllers(rootViewElement) { var elements = rootViewElement.querySelectorAll('[data-controller]'), i = 0, l = elements.length, ctrlName, ctrl, element; for(;i