Project

syringe

0.0
No commit activity in last 3 years
No release in over 3 years
If you needs a dependency injection container for Ruby, try use syringe.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.9
 Project Readme

syringe¶ ↑

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!

Special Thanks¶ ↑

Hey Jim Weirich, thanks for initial code and inspiration. You are the man!

onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc

Install¶ ↑

gem install syringe --pre -s http://gemcutter.org

Examples¶ ↑

First example with taste of service locator pattern¶ ↑

# 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

Second example with the best taste of dependency injection¶ ↑

# 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'

See more on¶ ↑

github.com/leandrosilva/syringe/tree/master/spec

Copyright © 2010 Leandro Silva (CodeZone) <leandrodoze@gmail.com>. See LICENSE for details.