Coder Social home page Coder Social logo

syringe's Introduction

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) <[email protected]>. See LICENSE for details.

syringe's People

Contributors

leandrosilva avatar

Stargazers

Darshan Sawardekar avatar  avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.