Project

codeine

0.0
No commit activity in last 3 years
No release in over 3 years
A really simple, partitionable, ruby-flavored dependency injector
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Codeine

A simple dependency injector for ruby projects.

Despite how flexible ruby is, and the insistence of some seriously smart people, I frequently run into the need on larger projects to centrally manage my dependencies. I end up building something like Codeine for each one, so I decided to build it one more time and re-use it.

It turns out I agree with basically everything Alexey Petrushin wrote here

Usage

Codeine can operate as either a global or module-local dependency container. Using it globally is the least flexible, but presents the simplest syntax.

require 'codeine'
Codeine.register(:logger){Logger.new}

class Foo
  codeine_inject :logger
  
  def initialize
    logger.log "Initialized..."
  end
end

For library code, and for larger projects, it's probably a better idea to segregate the containers.

require 'codeine'


module ProjectA
  class Foo
    codeine_inject :logger

    def initialize
      logger.log "Initialized..."
    end
  end
end

Codeine.configure(ProjectA) do
  c.register(:logger){Logger.new}
end

foo = ProjectA::Foo.new

The container bound to the ProjectA module will only service injection requests from classes/modules that reside within it