A very lightweight dependency injection container for Ruby.
It born from a real need in one of my current projects (at Locaweb). I’m only scratching our itch. If you have the same itch, join us!
Hey Jim Weirich, thanks for initial code and inspiration. You are the man!
onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc
gem install syringe --pre -s http://gemcutter.org
# on application bootstrap container = Syringe::Container.new container.register(:service_uri) { |container| 'http://services.syringe.org/api' } container.register(:service_consumer) { |container| ServiceConsumer.new(container[:service_uri]) } ... # anywhere in the code puts container[:service_uri] # http://services.syringe.org/api puts container.service_uri # http://services.syringe.org/api
# on application bootstrap default_container = Syringe::Container.default default_container.register(:service_uri) { |container| 'http://services.syringe.org/api' } ... # in some class class ServiceConsumer inject :service_uri # it will create a new method and instance variable with that name end ... # anywhere in the code service_consumer = ServiceConsumer.new puts service_consumer.service_uri # 'http://services.syringe.org/api'
github.com/leandrosilva/syringe/tree/master/spec
Copyright © 2010 Leandro Silva (CodeZone) <[email protected]>. See LICENSE for details.