RAA - mindi/0.3

mindi / 0.3

Short description: Minimalist dependency injection
Category: Library/Development
Status: beta
Created: 2004-12-06 01:50:41 GMT
Last update: 2006-04-30 00:27:54 GMT
Owner: Joel VanderWerf (Projects of this owner)
Homepage: http://redshift.sourceforge.net/mindi/
Download: http://redshift.sourceforge.net/mindi/
License: Ruby's
Dependency:
None
Description:

MinDI

MinDI is Minimalist Dependency Injection for Ruby. It is inspired by Jamis Buck’s Needle (needle.rubyforge.org) and Jim Weirich’s article on DI in Ruby (onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc).

MinDI is minimalist in that it attempts to map concepts of DI into basic ruby constructs, rather than into a layer of specialized constructs. In particular, classes and modules function as containers and registries, and methods and method definitions function as service points and services. There are some inherent advantages and disadvantages to this approach, discussed below.

MinDI builds on this minimal DI container by adding the InjectableContainer concept, which is a kind of DI available only in dynamic languages: through the magic of method_missing, a service may invoke other services without having explicit setter or constructor references to those services.

Synopsis

Using the BasicContainer module for constructor injection:

  require 'mindi'

  class SimpleContainer
    include MinDI::BasicContainer

    greeting { "Hello, world\n" }

    point_at { |x,y| [x,y] }

    stuff { [greeting, point_at(100,200)] }
  end

  cont = SimpleContainer.new

  p cont.stuff   # ==> ["Hello, world\n", [100, 200]]

Using the InjectableContainer module for "dynamic" or "fallback" injection, using method_missing:

  require 'mindi'

  class Transformer
    def transform string
      string.gsub(pattern, &replacement)
    end
  end

  class TransformerContainer
    include MinDI::InjectableContainer

    pattern     { /foo/ }
    replacement { proc {|match| match.upcase } }
    transformer { Transformer.new }
    transform   { |str| transformer.transform(str) }
  end

  cont = TransformerContainer.new
  s1 = cont.transform("fo foo fee")
  s2 = cont.transform("fo foo fee")
  p s1              # ==> "fo FOO fee"
  p s1.equal?(s2)   # ==> true

RELEASE-NOTES

mindi 0.3

  • Allow nil and false as service values. This allows limited rake-like functionality—see examples/rake-alike.rb.
  • Can now include MinDI::BasicContainer instead of extend MinDI::Container, for convenience.
  • Lots of examples.

mindi 0.2

  • Injectable containers. See examples/inject.rb. Note that including the MinDI::Injectable module not only provides this new functionality but also extends with MinDI::Container
  • Because of the above change, including MinDI::Injectable is now the recommended way of using MinDI.

mindi 0.1

  • first release
Versions: [0.3 (2006-04-30)] [0.1 (2004-12-06)]

Edit this project (for project owner)

back to RAA top