Skip to content

Instantly share code, notes, and snippets.

@kentaromiura
Created February 9, 2010 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentaromiura/299395 to your computer and use it in GitHub Desktop.
Save kentaromiura/299395 to your computer and use it in GitHub Desktop.
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