Project

smithy

0.0
No commit activity in last 3 years
No release in over 3 years
A simple Dependency Injection container for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 2.10.0
 Project Readme

Smithy

Smith is an Inversion of Control (IoC) container for Ruby. It's based on an example given in Jim Weirich's Dependency Injection: Vitally Important or Totally Irrelevant talk at O'REILLY OSCON 2005. He called the example matzdi_constructor so, presumably, Matz was involved as well.

Installation

Add this line to your application's Gemfile:

gem 'smithy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install smithy

Usage

require "rubygems"
require "bundler/setup"

require "logger"
require "smithy"

class LoggingErrorReporter
  def initialize(logger)
    @logger = logger
  end

  def report(error)
    @logger.error("badness: #{error}")
  end
end

container = Smithy::Container.new
container.register(:logger, Logger.new($stdout)) # you can register literal objects
container.register(:error_reporter, LoggingErrorReporter, :logger) # you can also register classes

container.instance(:error_reporter).report("no more coffee")

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request