[update 28/04/2012]The dijon demo app was included in TodoMVC’s labs section[/update]
Basically it’s an object registry, that allows you to define how and when objects are instantiated, functions and handlers are called and what objects should be passed on to other objects (that’s the injection thingy).
Dijon is not v1.x yet, but it is stable to use.
- Framework independent: doesn’t rely on any other 3rd party frameworks
- Framework integration: easily used on top of other frameworks
- Coding style independent: can be used in class-based or module pattern style.
- Routing: flexible enough to be used as a router
- MVC: although there are no specific classes or functions that enforce an MVC structure on your code, Dijon was specifically created to facilitate easy MVC(S) structure setup. (See Demo)
- Instead of DI the Service Locator pattern can be used as well.
//create a dijon.System instance var system = new dijon.System(); //register an object to be used as a singleton factory system.mapSingleton( 'userModel', UserModel ); system.mapSingleton( 'loginController', LoginController ); //to have the UserModel instance injected into another object //you'll need to define an outlet system.mapOutlet( 'userModel', 'loginController', 'currentUser' ); //this registers 'currentUser' as an injection point in LoginController instances to be satisfied with the //instance of UserModel //you can register functions of mapped objects as event handlers system.mapHandler( 'Context#startup', 'loginController', 'loginUser' ); //when 'Context#startup' is dispatched the 'loginUser' method of 'loginController' will be called //no instances have been created yet //it's only when we call the 'Context#startup' event, an instance of LoginController will be created //and since it has a dependency on UserModel, the singleton instance of UserModel will be created //as well system.notify( 'Context#startup' );