Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var IOC = new Class({
initialize:function(){
this.container = {};
},
register:function(id, component, options){
if($type(id) != 'string')throw new Error("No id to register");
if(!$chk(component))throw new Error("No component to register");
var o = options || {type:'singleton'};
this.container[id] = {type:o.type, component:component};
},
find:function(id){
return this.container[id];
},
byConstructor:function(){
var args = [].slice.call(arguments);
var o = this.find(args.shift());
var Obj = o.component;
if(o.type == 'singleton'){
if(!o.instance){
o.instance = Obj.Invoke(args);
}
return o.instance;
}else{
return Obj.Invoke(args);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment