Skip to content
Enable Guice-like dependency injection and contextual object interactions.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
doc
lib
rake_tasks
scratch
spec
src
.gitignore
.rvmrc
CHANGELOG
Gemfile
NOTES.txt
README.md
Rakefile
TODO
TODO.txt
conject.gemspec

README.md

Object Context

Retrieve and relate objects within contexts. Provides dependency injection convenience inspired by the simplicity of Google's Guice.

Example: Basic composition

require 'conject'

class Wood
  def to_s; "Wood"; end
end

class Nails
  def to_s; "Nails"; end
end

class Fence
  construct_with :wood, :nails

  def to_s
    "I'm made of #{wood} and #{nails}"
  end
end

fence = Conject.default_object_context.get(:fence)
puts fence
#=> "I'm made of Wood and Nails"

Example: Modules as namespaces

module Chart
  class Presenter
    construct_with 'chart/model', 'chart/view'

    def to_s
      "I'm a Chart::Presenter composed of a #{model} and a #{view}"
    end
  end
end
Something went wrong with that request. Please try again.