# "
mmm# mmm
#" "# #
# # #
"#m## mm#mm
di is a simple and well tested javascript / coffeescript dependency injection container. it supports shared / non shared services and tags. it's written in a few lines of coffeescript, but feel free to copy the javascript source as well.
install
just grab the di.coffee or .js.
license
New BSD License
examples
default configuration
# some example classes : -> "hello from a" : : -> "hello from b and " + @ahello : @ : -> @ahello i = 0 # create and configure the di d = dconfigure factories: : -> # constructor injection : digetA # setter injection : setA digetA notShared: shared: false : -> i++ : -> i++ expectdgetBhellotoBe "hello from b and hello from a"expectdgetDemoSetterInjectionhellotoBe "hello from a" # services are shared by default expectitoBe0dgetShareddgetShareddgetSharedexpectitoBe1 # there is also support for non-shared services dgetNotShareddgetNotSharedexpectitoBe3 # HINTS # getA returns a function that returns the service for laziness. # getA is the same like get('a') # getA() is the same like get('a')()
tags
d = dconfigure factories: pluginA: tag: "Plugin" : -> "a" pluginB: tag: "Plugin""you can have more than one tag :)" : -> "b" somethingElse: -> "c" # now get all "Plugins" :) tags = dgetByTag'Plugin'expecttags0toBe "a"expecttags1toBe "b"