Are there any inversion of control frameworks for javascript? Are there any inversion of control frameworks for javascript? javascript javascript

Are there any inversion of control frameworks for javascript?


I started writing one that I never got around to finishing. Not sure if I ever will as the overhead probably isn't worth it. if you're interested, it's at: http://code.google.com/p/jasproject/wiki/JasFac (that's the IoC portion, the full suite is at http://code.google.com/p/jasproject/)

The mocking library is fairly complete (no expectations though, at the moment i just use assertions on the mocks/stubs) but the unit testing framework is lacking. The IoC portion is pretty complete but might have a few bugs (don't think so though)

Feel free to use it and/or contribute, I can help where you need.

EDIT: More usage can be seen in the unit tests for jasfac: https://jasproject.googlecode.com/svn/trunk/Jas.Tests/JasFacTests.js


I was looking for one last year and ran across squirrel-ioc. There was something I didn't like about it - I think it only supported singleton style instances.

Squirrel is an IoC container implemented in Javascript to promote the better use of architecture and patterns in browser-based Javascript applications

I started writing my own and got pretty far (constructor and setter injection, values and reference relationships, singleton support, JsUnit tests) but never really needed it in my application. I may have to check out Luke's project. For reference, here is an example of the configuration format I ended up with.

var iocConfig = {  "a" : { Type : A },  "b1" : { Type : B, Props : [{Name : 'Letter', Ref : "a"}]  },  "b2" : { Type : B, Props : [{Name : 'Letter', Val : "a"}]  },  "c2" : { Type : C, Args : [{Ref : "a"}, {Val : "a"}]  },  "d" : { Type : D, Props : [{Name : 'Letter', Ref : "a"}]  },  "date" : { Type : Date, Props : [{Name : 'FullYear', Val : 2008}, {Name : 'Month', Val : 0}, {Name : 'Date', Val : 1}]  },  "array3" : { Type : Array, Args : [{Val : 3}]  },  "number1" : { Type : Number, Args : [{Val : 1}]  },  "string1" : { Type : String, Args : [{Val : "1"}]  },  "s-true" : { Type : S, Singleton : true},  "s-false" : { Type : S, Singleton : false}};


I put together a simple lightweight ioc container, called it JsfIoc.

http://github.com/fschwiet/JsfIoc